I've copied an old VBS code from here, but it seems to be not working. I know nothing of VBS so I'm lost here.
It seems to be very simple, it opens a text file, changes the values according to what was written before (it just "flips a bit"), removes the old file then writes the new one. It seems to be having issues with closing the file it created, and it never creates
It's giving an error on Line 42, with the code
800A01A8, "Object Required: '' ".
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 = "ToggleLidAction2.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 = "ToggleLidAction2.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 "ToggleLidAction2.bat C:\WINDOWS\system32\cmd.exe", 0