Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need a little editing help please. 1

Status
Not open for further replies.

UglyDogNH

IS-IT--Management
Jul 11, 2011
21
US
I got a scrpt that will turn off most of my Power Options for XP users. BUT I need some help to turn off "Always show icon" and "Promt for password". My script is below and any help woould be appriciated. Thanks

' Power Management Profiles:
' 0 = Home/Office Desk
' 1 = Portable/Laptop
' 2 = Presentation
' 3 = Always On
' 4 = Minimal Power Management
' 5 = Max Battery
' 6 = Custom Profile

Dim intSleepTime

intSleepTime = 5000

Set WshShell = WScript.CreateObject("WScript.Shell")

' Set the Default to be "Home/Office Desk"
' Turn on Hibernation

WshShell.Run "%COMSPEC% /c POWERCFG /SETACTIVE ""Home/Office Desk"""
WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate OFF"


' Start changing Power Management profiles' settings

' Change "Home/Office Desk" profile settings
WshShell.Run "%COMSPEC% /c POWERCFG /CHANGE ""Home/Office Desk"" /monitor-timeout-ac 0 /monitor-timeout-dc 0 /disk-timeout-ac 0 /disk-timeout-dc 0 /standby-timeout-ac 0 /standby-timeout-dc 0 /hibernate-timeout-ac 0 /hibernate-timeout-dc 0 /processor-throttle-ac none /processor-throttle-dc adaptive"
WScript.Sleep intSleepTime



' Cleanup

Set WshShell = Nothing

WScript.Quit(0)
 
These setting are not global. They are apart of each users' hive. Therefore, they need to be changed within the Local User Configuration. However, these setting can be pushed user GPO.

"Prompt for Password"
Policy\User Configuration\Administrative Templates\Control Panel\Personalization\Password protect the screen saver : Enable

"Always show icon"
Policy\User Configuration\Administrative Templates\Start Menu and Taskbar\Remove the battery icon : Enable

not sure where the reg keys are.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
always show icon"
HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\SysTray\Services

In my environment, the icon is off and the value is 1e(30). When the icon is turned on the value is 1f(31). That being said.

Navigate to this key and toggle the "always show icon" check box in the control panel \ power options. Once toggled, refresh the registry (F5) to see the new value

"Prompt for password"
HKCU\Control Panel\Desktop\ScreenSaverIsSecure
I assume you are referring to screen saver


Code:
CONST HKCU = &H80000001
strComputer = "."

set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

objReg.SetDWORDValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Applets\SysTray", "Services", 30

objReg.SetStringValue HKCU, "Control Panel\Desktop", "ScreenSaverIsSecure", 1

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
OOPS! My mistake or I'm just writing the script wrong.
Could I please have some help. How would I put this whole script together so it will work?
Thanks for your assistance.
 
put the above in a their own subs and call the subs when you want. Something like...

Code:
sub setPowerTheme
	' Power Management Profiles:
	' 0 = Home/Office Desk
	' 1 = Portable/Laptop
	' 2 = Presentation
	' 3 = Always On
	' 4 = Minimal Power Management
	' 5 = Max Battery
	' 6 = Custom Profile
	
	Dim intSleepTime
	
	intSleepTime = 5000
	
	Set WshShell = WScript.CreateObject("WScript.Shell")
	
	' Set the Default to be "Home/Office Desk"
	' Turn on Hibernation
	
	WshShell.Run "%COMSPEC% /c POWERCFG /SETACTIVE ""Home/Office Desk"""
	WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate OFF"
	
	
	' Start changing Power Management profiles' settings
	
	' Change "Home/Office Desk" profile settings
	WshShell.Run "%COMSPEC% /c POWERCFG /CHANGE ""Home/Office Desk"""
end sub

sub setOptions
	CONST HKCU = &H80000001
	set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
	objReg.SetDWORDValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Applets\SysTray", "Services", 31
	objReg.SetStringValue HKCU, "Control Panel\Desktop", "ScreenSaverIsSecure", 1
end sub


setPowerTheme
setOptions

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Geates,
First I want to thank you for your help. Obviously I’m new to scripting and still haven’t got it all figured out. I did what you said and my code now looks like this :

sub setPowerTheme
' Power Management Profiles:
' 0 = Home/Office Desk
' 1 = Portable/Laptop
' 2 = Presentation
' 3 = Always On
' 4 = Minimal Power Management
' 5 = Max Battery
' 6 = Custom Profile

Dim intSleepTime

intSleepTime = 5000

Set WshShell = WScript.CreateObject("WScript.Shell")

' Set the Default to be "Home/Office Desk"
' Turn on Hibernation

WshShell.Run "%COMSPEC% /c POWERCFG /SETACTIVE ""Home/Office Desk"""
WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate OFF"


' Start changing Power Management profiles' settings

' Change "Home/Office Desk" profile settings
WshShell.Run "%COMSPEC% /c POWERCFG /CHANGE ""Home/Office Desk"" /monitor-timeout-ac 0 /monitor-timeout-dc 0 /disk-timeout-ac 0 /disk-timeout-dc 0 /standby-timeout-ac 0 /standby-timeout-dc 0 /hibernate-timeout-ac 0 /hibernate-timeout-dc 0 /processor-throttle-ac none /processor-throttle-dc adaptive"
WScript.Sleep intSleepTime

End Sub

sub setOptions
CONST HKCU = &H80000001
set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.SetDWORDValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Applets\SysTray", "Services", 31
objReg.SetStringValue HKCU, "Control Panel\Desktop", "ScreenSaverIsSecure", 1
end sub


setPowerTheme
setOptions

It changes the Home Office Desk setting them all to NEVER. However the second part of the code which you supplied is not kicking in. Can you show me what I’m doing wrong?
Thanks
 
Geates: said:
Navigate to this key and toggle the "always show icon" check box in the control panel \ power options. Once toggled, refresh the registry (F5) to see the new value

Open regedit and navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\SysTray. Note the value. Open Power Options from the control panel and toggle the icon option. go back to the registry and note the new value.

objReg.SetDWORDValue HKCU, "Software\Microsoft\Windows\CurrentVersion\Applets\SysTray", "Services", somevalue

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hi Again,
I went to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\SysTray. I checked the box in power options and refreshed the registry. I unchecked the box in power options and refreshed the registry again. There was no change. It remains 31 in all cases.
 
After you checked the option, did you press 'OK' in the dialog before refreshing the registry view?
 
DAH! No. I'm an incredible idiot.
Thanks.

It did switch to 30 instead of 31. I changed the code and it still does no work.
 
It's likely because pressing OK reloads the registry. A log off/on may be required. The following code is supposed to reload the registry, however, it has worked for me in the past

Code:
objShell.Run "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
After considerable testing, the "prompt for password" is not located at HKCU\Control Panel\Desktop\ScreenSaverIsSecure, but rather the 80th bit of HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power\ACPolicy and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power\DCPolicy as well as the bit 172 of HKCU\Control Panel\PowerCfg\GlobalPowerPolicy\Policies.

How to change them via a script? still working on it. Maybe someone else knows the answer.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Prompt for Password doesn't seem to be available in XPSP3. Where can I find the one to which you are referring?

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
uh...

To enable:
POWERCFG /GLOBALPOWERFLAG on /OPTION RESUMEPASSWORD
To disable:
POWERCFG /GLOBALPOWERFLAG off /OPTION RESUMEPASSWORD

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Yes! Yes! Thank You!
Now, how do I put
POWERCFG /GLOBALPOWERFLAG off /OPTION RESUMEPASSWORD
into my script?
I think it would go here but I am not sure. I've tried different coding but I can't get it to work.
WshShell.Run "%COMSPEC% /c POWERCFG /SETACTIVE ""Home/Office Desk"""
WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate OFF"
 
yes, run it the same why you did the other powercfg commands.

Code:
WshShell.Run "%COMSPEC% /c POWERCFG /GLOBALPOWERFLAG off /OPTION RESUMEPASSWORD"

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I feel like freakin Dr Frankenstein yelling IT'S ALIVE! IT'S ALIVE!
Thank you very muck Geates for all your help. Here is the final code:

' Power Management Profiles:
' 0 = Home/Office Desk
' 1 = Portable/Laptop
' 2 = Presentation
' 3 = Always On
' 4 = Minimal Power Management
' 5 = Max Battery
' 6 = Custom Profile

Dim intSleepTime

intSleepTime = 5000

Set WshShell = WScript.CreateObject("WScript.Shell")

' Set the Default to be "Home/Office Desk"
' Turn on Hibernation

WshShell.Run "%COMSPEC% /c POWERCFG /SETACTIVE ""Home/Office Desk"""
WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate OFF"
WshShell.Run "%COMSPEC% /c POWERCFG /GLOBALPOWERFLAG off /OPTION RESUMEPASSWORD"

' Start changing Power Management profiles' settings

' Change "Home/Office Desk" profile settings
WshShell.Run "%COMSPEC% /c POWERCFG /CHANGE ""Home/Office Desk"" /monitor-timeout-ac 0 /monitor-timeout-dc 0 /disk-timeout-ac 0 /disk-timeout-dc 0 /standby-timeout-ac 0 /standby-timeout-dc 0 /hibernate-timeout-ac 0 /hibernate-timeout-dc 0 /processor-throttle-ac none /processor-throttle-dc adaptive"
WScript.Sleep intSleepTime


' Cleanup

Set WshShell = Nothing

WScript.Quit(0)
 
Glad it worked.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top