I am looking for how to make several changes in windows control panel settings on a computer running Windows 7, by using a batch file (without powershell).
The required settings are :
In PowerCFG Panel :
- Monitor Timeout on AC (switch to Disable)
- HDD Timeout on AC (switch to Disable)
- Standby Timeout on AC (switch to Disable)
- Hibernate Timeout on AC (switch to Disable)
- Action of the hardware power button (switch to Disable)
In Start Menu Panel :
- Action of the shutdown button (switch to Change User)
I have already tried this script :
@Echo Off
POWERCFG /CHANGE monitor-timeout-ac 0
POWERCFG /CHANGE disk-timeout-ac 0
POWERCFG /CHANGE standby-timeout-ac 0
POWERCFG /CHANGE hibernate-timeout-ac 0
exit
But I did not find how to get the others settings.
Thank you Forward
Before I explain you my solutions, I would advise you to copy the current power scheme and work with that copy instead of changing the current scheme. The current scheme may be a default scheme and changing without backup is sometimes risky. Undoing configuration changes is not always that easy.
I have 2 solutions I would like to share with you. The first one presents a solution for the hardware power button. It may also be a solution for the shutdown in the start menu but I couldn't set it on "Change User". I only tested it on a Windows 10 machine however (I had no Windows 7 machine to test it on) so there is a possibility that it could even be working for the start menu button on a windows 7 (could someone confirm this?). The problem is that it seems like the shutdown button in the start menu from windows 10 is not really the same as in windows 7 (windows 10 has 2 separate buttons in its start menu: one for the the log off and switch user, and one for the shutdown, sleep and restart; windows 7 has one button for all options).
The second solution is a second option for the shutdown in the start menu that surely works for Windows 7 (I used it some time ago).
Both solutions may require a restart, espacially the first one.
There actually are more settings you can change with
powercfg
then the ones available with the/CHANGE
(or-change
or-x
) flags. The hardware power button is one of them. There is also a setting for the shutdown button in the start menu but I'm not sure if it can help. Anyway, to check all settings you can change for a power scheme you'll need the power scheme's GUID (a 36 character long ID).powercfg
always gives you the possibility to use aliases instead of GUID. You can choose but GUIDs have a specific form that makes it easier to use in scripts (except maybe for some cases). The aliases are just easier to read, understand and remember.To search for the GUID of a scheme you can use:
powercfg -list
which will print a string of the formPower Scheme GUID: <GUID> (<NAME POWER SCHEME>)
for each power scheme (name is not the same as alias). You can then usefindstr
to choose a specific power scheme name (or justpowercfg -getactivescheme
for only the active scheme) and use aFOR /F
to extract the GUID like this:Once you have the GUID (or alias) you can check its whole configuration with:
powercfg -q
(orpowercfg -q %activeschemeGUID%
with the variable from first code example) will give you the GUID, alias and (the long list of) all settings for the active scheme you can change and the values they can take (inpowercfg
they actually name it value index and not value).Settings are grouped in subgroups. Each subgroup and setting has a GUID. The most common subgroups and settings even have aliases. To check all avialable aliases for settings and subgroups you can use
powercfg -aliases
. You'll need the GUID (or the alias if available) to check which values a setting can take and its current value:or to change its value(s):
The first one will change the AC value index and the second one the DC (if available, check the values of the setting therefore).
The only thing you now need is the correct GUIDs for your settings (or aliases if available). I'll spare you the search time and give you the GUIDs on my side. They should be default but you can always look for them by searching the string "power" (case-insensitive search) in all available settings. The setting for the action of the hardware power button and the setting for the action of the shutdown button in the start menu both belong to the same subgroup: subgroup with alias
SUB_BUTTONS
and GUID4f971e89-eebd-4455-a8de-9e59040e7347
. The hardware button has aliasPBUTTONACTION
and GUID7648efa3-dd9c-4e3e-b566-50f929386280
. The start button has aliasUIBUTTON_ACTION
and GUIDa7066653-8d6c-40a8-910e-a1f54b84c7e5
. You can check them on the command line withpowercfg -aliases
.Before changing the settings, check which indices they can take on the command line:
If that doesn't work you should try with the GUIDs instead of the aliases or try to look up the correct GUIDs/aliases for your configuration. After you've seen which value indices you need, you can change the settings. In my case, disabling the hardware power button was index 0. So changing for respectively AC and DC was:
I had no log off option for the
UIBUTTON_ACTION
unfortunatly. So I can't show you that one but it would have been the same principle. That's also the reason why I'm not sure theUIBUTTON_ACTION
will do the trick for the start menu.For the shutdown button in the start menu, I know there is another option in windows 7: change the registry
Start_PowerButtonAction
located inHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
. I warn you: changing registries is delicate and not really good practice but sometimes it is the only way to change some configurations. I'm not sure but it may also require administrator priviliges so running as administrator may be necessary(can someone confirm this too?).These are the hexadecimal values the registry can take:
You can use
regedit
GUI to check the current value of the registry. Or check that value on the command line withreg
(EDIT: useHKCU
instead ofHKEY_CURRENT_USER
inreg
):After you checked the registry exists and has the value corresponding to your start menu shutdown button you can modify it. But before modifying any registry, make sure to back-up the registry with
regedit
(this official Windows link also offers help) in case something goes wrong.To modify the registry
Start_PowerButtonAction
and set "Change User" as action in batch you can use:If it didn't exist you can create it with the same command and try it out. If it doesn't work, use the back-up to restore at least the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
key.After you've tested it you can add those commands in a batch script. The final script would look like this:
PS: For the restart you can add the
shutdown
command at the end of your scrit before theexit
:will generate a restart after 60 seconds with the reason: "Operating System: Reconfiguration (Planned)". See this link for more info.
PPS: In case you use the registry solution, you can use the following to check if the script is running with administrator rights at the beginning of your script (if admin rights are required):
openfiles
is a command that always requires admin rights. If it fails you know the script hasn't been run as an administrator.