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.