2

I've made a vbs script which basically toggles the close lid action between Sleep and DoNothing.

The idea is to have an icon on my desktop to save going ControlPanel>PowerOptions>ChangeWhatClosingTheLidDoes every time. I'm on Windows 7 x64 by the way.

When I run it, in control panel I can see that the lid close action changes, however when I actually close the lid, there is no change in behavior.

Any suggestions on what could be preventing the system from obeying it's instructions??

It's really strange that I can see the change in ControlPanel>PowerOptions, but it doesn't work...

Video demo here, not sure how to embed... https://www.youtube.com/watch?v=N1yjiTMgnzk&feature=youtu.be

The vbs script basically checks what values are in a .bat file, reverses them and runs it. Really simple;

ToggleLidAction.vbs
Const ForAppending = 8
Const ForReading = 1

Dim outPutFile

Dim objFSO, objFile, objOutFile, strLine
dim sleepLine1, sleepLine2, doNothingLine1, doNothingLine2

sleepLine1 = "powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1"
sleepLine2 = "powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1"
doNothingLine1 = "powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0"
doNothingLine2 = "powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-  eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("ToggleLidAction.bat", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    strDoNothing = Instr(strLine,"powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685- ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0")
    strSleep = Instr(strLine,"powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-     ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1")
Loop
objFile.Close

Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile("ToggleLidAction.bat")

If strDoNothing Then
outPutFile = "ToggleLidAction.bat"
    Set objOutFile = objFSO.CreateTextFile(outPutFile,ForAppending)
    objOutFile.WriteLine ""& sleepLine1 &""
    objOutFile.WriteLine ""& sleepLine2 &""
    Msgbox ("The System will now Sleep when the lid is closed.")
else if strSleep Then
    outPutFile = "ToggleLidAction.bat"
    Set objOutFile = objFSO.CreateTextFile(outPutFile,ForAppending)
    objOutFile.WriteLine ""& doNothingLine1 &""
    objOutFile.WriteLine ""& doNothingLine2 &""
    Msgbox ("The System will now continue running when the lid is closed.")
end if
end if
objOutFile.Close

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "ToggleLidAction.bat C:\WINDOWS\system32\cmd.exe", 0

ToggleLidAction.bat

powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0

or

powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-      9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1

Though I don't think it's a problem with the code, because as I said, and you can see on the video, I can see the change in Control Panel.

Thanks for reading,

Any suggestions greatly appreciated.

user3133275
  • 41
  • 1
  • 8
  • Well, eliminate the "code" from the problem. If you run the `powercfg` statements from a command line, does it work? – Bond May 30 '14 at 01:32
  • Sorry, should have put it in there. No, it has the exact same results. – user3133275 May 30 '14 at 11:36
  • You may want to remove all the VBScript code then and re-post your question more simply as a "Windows" or "Command Line" question, focusing just on your `powercfg` statement(s). You'll get better answers that way from people who understand `powercfg` but not VBScript. – Bond May 30 '14 at 14:50
  • Ok, will do. Thanks for your response... – user3133275 May 30 '14 at 16:51
  • New thread added here; http://stackoverflow.com/questions/23959861/computer-not-obeying-powercfg-guid-command-line-instructions If anybody has any suggestions, thanks... – user3133275 May 30 '14 at 17:06

1 Answers1

2

Copied from the comment found on this deleted question:

Turns out what was missing was powercfg -setactive.

powercfg needs one of those to update changes to the current scheme. So to change your settings via cmd line/batch file you would need to run:

powercfg -setacvalueindex Scheme_GUID Sub_GUID Setting_GUID SettingIndex

followed by:

powercfg -setactive Scheme_GUID
Community
  • 1
  • 1
Makoto
  • 104,088
  • 27
  • 192
  • 230