UI Interest Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically Setting the Brightness on a Windows Machine

Well, I am not sure where this belongs, but it seems that the User Interface group might be the best place to stick it, so her it is...

I am currently developing a kiosk type application on a Windows machine (7 and 😎 in which the customer wants to limit access to the actual operating system.  As such, he wishes to be able to control the screen brightness through the user interface.  After a little mucking around, I was finally able to come up with something that does this through the Windows Management Instrumentation (WMI) infrastructure. 

The VI attached is fairly simple - it makes a call on the WmiMonitorBrightnessMethods class to set the brightness of the monitor through the method WmiSetBrightness.  The method takes two inputs using anonymous types - timeout (which here I have set to the maximum value of the 32 bit unsigned integer) and the brightness (a 0-100 value defined by a byte represented by a slider in the provided UI).  There is nothing fancy about the interface itself, but it does assist those looking for Labview programatic control of the brightness and I think that it might serve as yet another example of how to use .NET calls in the Labview environment.

Anyways, let me know if you have any thoughts.

EDIT 07/30/2014: The previous version left an open reference.  While not a problem if you are using something like this very rarely over short periods of time, this can create memory issues over time.  Current version is now in 2013.  Please let me know if you would like to see it in another version.

brightness Ui.png

brightness.png

Comments
djac91
Member
Member
on

nice work

-----------------------------------------------------------------------------------------------------------------------------
Waiting For the inner calling 🙂


TroyK
Active Participant
Active Participant
on

It looks interesting but it doesn't work for me. I get this:

Error 1172 occurred at Error calling method System.Management.ManagementObjectCollection+ManagementObjectEnumerator.MoveNext, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

    Inner Exception: System.Management.ManagementException: Not supported )

Possible reason(s):

LabVIEW:  A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation.

System.Management.ManagementException in WMI Set Brightness.vi

Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
cirrusio
Active Participant
Active Participant
on

Thanks for giving this a go, Troy.  1172 is the LV error code for internal .NET errors.  What version of Windows are you running?  (So far, I have tested this on 7 and 8.)  Is the service Winmgmt running?  What version of the .NET framework do you have on your computer?

Matt

TroyK
Active Participant
Active Participant
on

64bit Windows 7 Professional Service Pack 1

winmgmt service is running

Microsoft .NET Framework 4.5.1

I should add that no error occurs until I actually try to adjust the brightness, so it gets the references fine.

Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
cirrusio
Active Participant
Active Participant
on

Sorry that it has taken so long to get back to you Troy.  Unfortunately, it's not getting the references ok - this error is being thrown when it attempts to get a reference to the WmiMonitorBrightnessMethods class.  Two thoughts come to mind - something is wrong with the namespace path or there is a permissions issue.  I will look into whether something is going on with the path.

m

Arlon
Member
Member
on

Perhaps an easier way to do this would be to run the UI on top of a black background and programmatically set the transparency (Front Panel Window:Transparency Property). Of course, this will only dim the one window, but will work fine if that window is maximized and the Windows task bar is hidden. I ended up dynamically calling another VI to run behind to set the background colour.

cirrusio
Active Participant
Active Participant
on

Thanks Arlon.  This is just to demonstrate the capabilities of using the WMI infrastructure that is available on current Windows machines.  I have had no issues running this on several different Windows 7 and 8 machines and this is actually an extract of code that is currently being used on some production code where we want the entire screen to dim. Take a look at the code above - this is something that can be easily wrapped up and called (minus the event structure) via a functional global or something else and is not coupled to the current UI. 

That being said, your method has advantages - you could set the brightness to a much lower value (to black if necessary - but then your controls might be inaccessible) and the brightness can be set properly on multiple monitors.  I am certain that the second point could be overcome using WMI, but I haven't really looked into it.

AlbertoCam
Member
Member
on

Dear Mtat76. This wast just the code I have been looking for!!

Problem is that Im running with labview 2011. Could you post the version for the 2011 users?

thank you very much!!

bzman
Member
Member
on

Hi Mtat76. Having trouble running your code. LabVIEW can't seem to find System.Management.dll.  I've tried all the versions available on my computer (.NET Framework v4.0.3) and the v2.0.5, however I'm still getting an error. Any idea what .NET Framework version I need, or if your .NET constructors need something else entirely?

My system:

Win7 x64

LabVIEW 2014 SP1

bzman
Member
Member
on

UPDATE: I figured out the issue. It was a permissions problem due to the fact that my VI was on a network drive. I copied it to a local folder AND added it to a LabVIEW Project, then it has no trouble finding System.Management.dll

cirrusio
Active Participant
Active Participant
on

Great!  Let me know if you have any other issues!

Ajay_MV
Active Participant
Active Participant
on

The document here gives the similar brightness control using a wrapper DLL written in .NET

--
Ajay MV


magicbean
Member
Member
on

In case anyone is interested, I can confirm that this is sill running in LabVIEW 2021 on a Windows 11 PC.

 

I'd love to be able to set the screen brightness to 'completely black' though!

Contributors