Power Options Properties - Advanced
I'm running Windows XP on my Laptop machine. Here I need to change the Advanced setting for Power Options as Do Nothing for "When I close the lid of my portable computer" and "When I press the sleep button on my computer" automatically (not manually as need to configure this setting on multiple machines).
I tried to use powercfg.exe file to change the settings but its only work for Power Schemes. Can anyone provide me vbscript or batch script which change the advanced setting for Power Options as mentioned above.
I tried to use powercfg.exe file to change the settings but its only work for Power Schemes. Can anyone provide me vbscript or batch script which change the advanced setting for Power Options as mentioned above.
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
jmaclaurin
12 years ago
Assuming Active Directory is not an option, powercfg.exe supports command line options to do pretty much what you asked and it appears that you discovered that. As for someone writing a vbs script for you, thats not likely going to happen.
I would suggest you google something like:
how to create a vb script to install software
or
how to create a vb script to run an exe
Keep in mind that every line of every script has likely already been written somewhere. Learnig to read and assemble the script so it works in your environment is what you are looking for.
I would suggest you google something like:
how to create a vb script to install software
or
how to create a vb script to run an exe
Keep in mind that every line of every script has likely already been written somewhere. Learnig to read and assemble the script so it works in your environment is what you are looking for.
Comments:
-
I Had a look on the net and could not find much. Made a Script to do it and here it is.
On Error Resume Next
' Basic checks to see if this will even work and exit if not
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes"
strValueName = "ActivePowerScheme"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("c:\windows\system32\powercfg.exe") = False Then wscript.quit
If Err Then wscript.quit
' Call client os function to determine if it is a server or not
' This script needs modification to run against servers as it is
' meant only for client operating systems.
Dim strOS : strOS = isClientOperatingSystem()
If strOS = False Then wscript.quit
Dim objWshShell : Set objWshShell = WScript.CreateObject("WScript.Shell")
' Disable hibernate if it is enabled
If objFSO.FileExists("c:\hiberfil.sys") Then
If InStr(strOS,"XP") > 0 Then
objWshShell.Run "powercfg /hibernate off", 0, True
Else
objWshShell.Run "powercfg -h off", 0, True
End If
End If
' Turn off standby and monitor timeout (while plugged in)
If InStr(strOS,"XP") > 0 Or InStr(strOS,"2000") > 0 Then
' XP and 2000 specific settings
objWshShell.Run "powercfg /X " & chr(34) & "home/office desk" & chr(34) & _
" /standby-timeout-ac 0",0,True
objWshShell.Run "powercfg /X " & chr(34) & "home/office desk" & chr(34) & _
" /monitor-timeout-ac 0",0,True
objWshShell.Run "powercfg /setactive " & chr(34) & "home/office desk" & chr(34),0,True
Else
' Vista, 7
objWshShell.Run "POWERCFG /Hibernate off"
objWshShell.Run "POWERCFG -X -monitor-timeout-ac 25"
objWshShell.Run "POWERCFG -X -monitor-timeout-dc 25"
objWshShell.Run "POWERCFG -X -disk-timeout-ac 0"
objWshShell.Run "POWERCFG -X -disk-timeout-dc 30"
objWshShell.Run "POWERCFG -X -standby-timeout-ac 0"
objWshShell.Run "POWERCFG -X -standby-timeout-dc 120"
objWshShell.Run "POWERCFG -X -hibernate-timeout-ac 0"
objWshShell.Run "POWERCFG -X -hibernate-timeout-dc 0"
objWshShell.Run "powercfg -SETDCVALUEINDEX " & strValue & " 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0"
objWshShell.Run "powercfg -SETACVALUEINDEX " & strValue & " 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0"
objWshShell.Run "powercfg -SETACVALUEINDEX " & strValue & " fea3413e-7e05-4911-9a71-700331f1c294 0e796bdb-100d-47d6-a2d5-f7d2daa51f51 0"
objWshShell.Run "powercfg -SETDCVALUEINDEX " & strValue & " fea3413e-7e05-4911-9a71-700331f1c294 0e796bdb-100d-47d6-a2d5-f7d2daa51f51 0"
End If
' Clean house
Set objWshShell = Nothing
Set objFSO = Nothing
Private Function isClientOperatingSystem()
' Purpose: This will return true only if the system can be verified as a client OS
' Usage: strOS = isClientOperatingSystem()
' If strOS = False Then wscript.quit
Dim objWMIService, objItem, colItems
Dim strOS
On Error Resume Next
' WMI Connection to the object in the CIM namespace
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
' WMI Query to the Win32_OperatingSystem
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
' For Each... In Loop (Next at the very end)
For Each objItem in colItems
strOS = objItem.Caption
Next
' Below might be a better way but I want to make sure it is one of the operating systems that has been tested, YMMV
' InStr(strOS,"Server") > 0 Then isClientOperatingSystem = False
If InStr(strOS,"Windows 7") <> 0 Or InStr(strOS,"XP") <> 0 Or InStr(strOS,"2000 Professional") <> 0 Or InStr(strOS,"Vista") <> 0 Then
isClientOperatingSystem = strOS
Else
isClientOperatingSystem = False
End If
If Err.Number <> 0 Then isClientOperatingSystem = False
strOS = Empty
Set objItem = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
On Error GoTo 0
End Function - rplowe 12 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.