vb.net - Weird behavior of powercfg.exe when I execute it programatically -
to programtically set display brightness had 2 options :
- use
powerwriteacvalueindex
,powerwritedcvalueindex
api - use powercfg.exe
now, tried both, , both gave me same (weird) result. here's code i'm using :
psiinfo .filename = "powercfg" .useshellexecute = true .windowstyle = processwindowstyle.hidden .arguments = "-setacvalueindex " & guidcurscheme.tostring() & " " & subgroup_guid.guid_video_subgroup & " " & setting_guid.guid_dispbrightness & " " & psvalue.valueac end pproc = process.start(psiinfo)
where :
public const guid_video_subgroup string = "7516b95f-f776-4464-8c53-06167f40cc99" public const guid_dispbrightness string = "aded5e82-b909-4619-9949-f5d71dac0bcb" public structure powersetting public valueac string public valuedc string end structure dim psvalue powersetting
and guidcurscheme
guid of active power scheme, returned powergetactivescheme
api function. samething dc part, "-setdcvalueindex".
now weird behavior follow :
- if call code in button click handler event, set these values, not "general" screen brightness slider (and matter, display brightness). (somebody edits pictures links inside post please)
- if user clicks button second time, apply setting.
- if put code in loop run twice when user click button, still behave in (1)
- if try run same command manually command-line, run work fine.
this totally unexpected, don't know i'm doing wrong. gives exact same result when use powerwriteacvalueindex
, powerwritedcvalueindex
functions windows api.
maybe double-check syntax of argument letting app copy string clipboard. tiny typo ruins me.
also i'd check if application gets called 1 syswow or system32 (that depends on how compile app) can check exitcode or @ error-output get. error-output can captured this:
dim system.io.streamreader dim se system.io.streamreader se = myproc.standarderror = myproc.standardoutput myproc.waitforexit() msgbox(so.readtoend & vbcrlf & se.readtoend)
Comments
Post a Comment