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!

Help: Set Screensaver Options

Status
Not open for further replies.

j4ckl3

IS-IT--Management
Apr 30, 2002
33
0
0
US
I have a question that has been frustrating me for the past few days. My office has approximately 300 machines and after I installed Windows XP Service Pack 1a the screensaver options we had specified were reset. I would like to be able to change the screensaver options via vbscript, but I am having trouble accompishing this.

I need to change the following for each user logged in:
[ol]
[li]Set default screensaver[/li]
[li]Set default timeout to 20 mins.[/li]
[li]Password protect screensaver[/li]
[li]Hide Screensaver tab[/li]
[/ol]

Here is the script I currently have:
**********************************************************
Code:
'==========================================================================
'
' VBScript Source File -- Change Screensaver Password Protection
'
' NAME: enableScrSaverPswd.vbs
'
' AUTHOR: Jason Spirko , Black & Veatch
' DATE  : 10/20/2003
'
' COMMENT: enables the Screensaver Password Protection under HKCU
'
'==========================================================================

Option Explicit


' Define variables, objects and constants used throughout the script
'--------------------------------------------------------------------------
     ' objects
     Dim objRegistry, objShell
     
     Dim objLocator, objWMIService
     
     ' variables
     Dim strTagID, strPopupTitle, strKeyPath, strKeyPath2, strKeyPath3, nAns, nRet
     Dim nRet0, nRet1, nRet2, strValue1, strValue2
     Dim nRet3, nRet4, nRet5, nRet6
     Dim strValue3, strValue4, strValue5, strvalue6
     Dim nRet7, nRet8, nRet9, nRet10
     Dim strValue7, strValue8, strValue9, strValue10
     
     ' variables - registry reads
     Dim strHKLM2
     Dim strHKCU1, strHKCU3, strHKCU4, strHKCU5, strHKCU6
     Dim strHKU7, strHKU8, strHKU9, strHKU10
     
     ' constants
     Const HKCU = &H80000001
     Const HKLM = &H80000002
     Const HKU = &H80000003
     Const YesButton = 6
	Const QuestionMark = 32
	Const YesNo = 4

     strPopupTitle = "B&V ANAR - Enable Screensaver Password"
     strKeyPath = "Software\Policies\Microsoft\Windows\Control Panel\Desktop"
     strKeyPath2 = ".DEFAULT\Control Panel\Desktop"
     StrKeyPath3 = "Software\Microsoft\Windows\CurrentVersion\Policies\System"


' Set file system object variables
'--------------------------------------------------------------------------     
     Set objShell = CreateObject("Wscript.Shell")


' Prompt for TagID and change Screensaver Password Protection
'--------------------------------------------------------------------------
     ' what TagID do you want to change
     strTagID = InputBox("What TagID do you want to check?", strPopupTitle)
     
     ' create instance of registry object on remote PC
     Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
          strTagID & "\root\default:StdRegProv")

     ' get HKCU registry values
     nRet1 = objRegistry.GetDWORDValue(HKCU, strKeyPath3, "NoDispScrSavPage", strValue1)
     nRet3 = objRegistry.GetStringValue(HKCU, strKeyPath, "ScreenSaveActive", strValue3)
     nRet4 = objRegistry.GetStringValue(HKCU, strKeyPath, "ScreenSaverIsSecure", strValue4)
     nRet5 = objRegistry.GetStringValue(HKCU, strKeyPath, "ScreenSaveTimeOut", strValue5)
     nRet6 = objRegistry.GetStringValue(HKCU, strKeyPath, "SCRNSAVE.EXE", strValue6)

     ' get HKU registry values
     nRet7 = objRegistry.GetStringValue(HKU, strKeyPath2, "ScreenSaveActive", strValue7)
     nRet8 = objRegistry.GetStringValue(HKU, strKeyPath2, "ScreenSaverIsSecure", strValue8)
     nRet9 = objRegistry.GetStringValue(HKU, strKeyPath2, "ScreenSaveTimeOut", strValue9)
     nRet10 = objRegistry.GetStringValue(HKU, strKeyPath2, "SCRNSAVE.EXE", strValue10)
     
     ' get HKLM registry values
     nRet2 = objRegistry.GetDWORDValue(HKLM, strKeyPath3, "NoDispScrSavPage", strValue2)

     
' Echo registry results
'--------------------------------------------------------------------------
     ' HKEY Local Machine Values
     ' NoDispScrSavPage
     If nRet2 = 0 Then
          Select Case strValue2
               Case "0"
                    strHKLM2 = "Screensaver tab is enabled"
               Case "1"
                    strHKLM2 = "Screensaver tab is disabled"
               Case Else
                    strHKLM2 = "Could not determine screensaver tab status"
          End Select
     Else
          strHKLM2 = "Could not find registry value: NoDispScrSavPage"
     End If
     
     
     ' HKEY_Current_Users Values
     ' NoDispScrSavPage
     If nRet1 = 0 Then
          Select Case strValue1
               Case "0"
                    strHKCU1 = "Screensaver tab is enabled"
               Case "1"
                    strHKCU1 = "Screensaver tab is disabled"
               Case Else
                    strHKCU1 = "Could not determine screensaver tab status"
          End Select
     Else
          strHKCU1 = "Could not find registry value: NoDispScrSavPage"
     End If
     
     ' ScreenSaveActive
     If nRet3 = 0 Then
          Select Case strValue3
               Case "0"
                    strHKCU3 = "Screensavers are not active"
               Case "1"
                    strHKCU3 = "Screensaver is active"
               Case Else
                    strHKCU3 = "Could not determine screensaver status"
          End Select
     Else
          strHKCU3 = "Could not find registry value: ScreenSaveActive"
     End If

     ' ScreenSaverIsSecure
     If nRet4 = 0 Then
          Select Case strValue4
               Case "0"
                    strHKCU4 = "Screensavers are not password-protected"
               Case "1"
                    strHKCU4 = "All screen savers are password-protected"
               Case Else
                    strHKCU4 = "Users can turn password-protection on and off"
          End Select
     Else
          strHKCU4 = "Could not find registry value: ScreenSaverIsSecure"
     End If

     'ScreenSaveTimeOut
     If nRet5 = 0 Then
          strHKCU5 = "Screensaver timeout is " & strValue5
     Else
          strHKCU5 = "Could not find registry value: ScreenSaveTimeOut"
     End If     
     
     'SCRNSAVE.EXE
     If nRet6 = 0 Then
          strHKCU6 = "Current Screensaver: " & strValue6
     Else
          strHKCU6 = "Could not find registry value: SCRNSAVE.EXE"
     End If


     ' HKEY_USERS Values
     ' ScreenSaveActive
     If nRet7 = 0 Then
          Select Case strValue7
               Case "0"
                    strHKU7 = "Screensavers are not active"
               Case "1"
                    strHKU7 = "Screensaver is active"
               Case Else
                    strHKU7 = "Could not determine screensaver status"
          End Select
     Else
          strHKU7 = "Could not find registry value: ScreenSaveActive"
     End If

     ' ScreenSaverIsSecure
     If nRet8 = 0 Then
          Select Case strValue8
               Case "0"
                    strHKU8 = "Screensavers are not password-protected"
               Case "1"
                    strHKU8 = "All screen savers are password-protected"
               Case Else
                    strHKU8 = "Users can turn password-protection on and off"
          End Select
     Else
          strHKU8 = "Could not find registry value: ScreenSaverIsSecure"
     End If

     'ScreenSaveTimeOut
     If nRet9 = 0 Then
          strHKU9 = "Screensaver timeout is " & strValue9
     Else
          strHKU9 = "Could not find registry value: ScreenSaveTimeOut"
     End If     
     
     'SCRNSAVE.EXE
     If nRet10 = 0 Then
          strHKU10 = "Current Screensaver: " & strValue10
     Else
          strHKU10 = "Could not find registry value: SCRNSAVE.EXE"
     End If


' Prompt for change confirmation
'--------------------------------------------------------------------------
     nAns = objShell.Popup(_
     "The computer " & strTagID & " screensaver settings are as follows:" & vbCRLF & vbCRLF & _
          "HKEY_LOCAL_MACHINE:" & vbCRLF & _
          "   *   " & strHKLM2 & vbCRLF & vbCRLF & _
          "HKEY_CURRENT_USER:" & vbCRLF & _
          "   *   " & strHKCU1 & vbCRLF & _
          "   *   " & strHKCU3 & vbCRLF & _
          "   *   " & strHKCU4 & vbCRLF & _
          "   *   " & strHKCU5 & vbCRLF & _
          "   *   " & strHKCU6 & vbCRLF & vbCRLF & _
          "HKEY_USERS:" & vbCRLF & _
          "   *   " & strHKU7 & vbCRLF & _
          "   *   " & strHKU8 & vbCRLF & _
          "   *   " & strHKU9 & vbCRLF & _
          "   *   " & strHKU10 & vbCRLF & vbCRLF & _          
     "Do you want to modify " & strTagID & " to include the following registry changes?" & vbCRLF & _
          "   *   ScreenSaveTimeOut: 1200" & vbCRLF & _
          "   *   ScreenSaverIsSecure: 1" & vbCRLF & _
          "   *   SCRNSAVE.EXE: logon.scr" & vbCRLF & _
          "   *   ScreenSaveActive: 1" & vbCRLF & _
          "   *   NoDispScrSavPage: 1" & vbCRLF & vbCRLF,, _
          strPopupTitle, QuestionMark + YesNo)
     
     If nAns = YesButton Then
          ' Set HKLM Values
          nRet = objRegistry.CreateKey(HKLM, strKeyPath3)
          nRet = objRegistry.SetDWORDValue(HKLM, strKeyPath3, "NoDispScrSavPage", "1")
          ' Set HKCU Values
          nRet = objRegistry.CreateKey(HKCU, strKeyPath3)
          nRet = objRegistry.SetDWORDValue(HKCU, strKeyPath3, "NoDispScrSavPage", "1")
          nRet = objRegistry.CreateKey(HKCU, strKeyPath)
          nRet = objRegistry.SetStringValue(HKCU, strKeyPath, "ScreenSaveActive", "1")
          nRet = objRegistry.SetStringValue(HKCU, strKeyPath, "ScreenSaverIsSecure", "1")
          nRet = objRegistry.SetStringValue(HKCU, strKeyPath, "ScreenSaveTimeOut", "1200")
          nRet = objRegistry.SetStringValue(HKCU, strKeyPath, "SCRNSAVE.EXE", "logon.scr")
          ' Set HKU Values
          nRet = objRegistry.SetStringValue(HKU, strKeyPath2, "ScreenSaveActive", "1")
          nRet = objRegistry.SetStringValue(HKU, strKeyPath2, "ScreenSaverIsSecure", "1")
          nRet = objRegistry.SetStringValue(HKU, strKeyPath2, "ScreenSaveTimeOut", "1200")
          nRet = objRegistry.SetStringValue(HKU, strKeyPath2, "SCRNSAVE.EXE", "logon.scr")
          MsgBox "Screensaver settings have been applied.",, strPopupTitle
     Else
          MsgBox "Screensaver settings cancelled.",, strPopupTitle
     End If
     
WScript.Quit()



' *******************************  END OF SCRIPT  *******************************

The problem is that even though the script says it changes the settings, they do not change. Any help would be appreciated. ;-)



------------------------------------------------------------------------------
nobody knows everything about IT, so make a point to help your fellow members

-= j@ckle =-
 
Hello j4ckl,

Just browser through your script, my preliminary comments would be:

[1] You have to make sure that the path of the HKU where screensaver's parameters are stored. My impression is it doesn't look right.
[2] You do not change HKCU on a remote machine. You should target more on .default if for future new users etc and HKU personal setting for each user.

regards - tsuji
 
I understand that HKCU is just an alias to the matching user SID stored under HKU. I would like to modify these setting for all users that have logged in. Does anyone know if this can be done?

------------------------------------------------------------------------------
nobody knows everything about IT, so make a point to help your fellow members

-= j@ckle =-
 
You access the remote with your credential. HKCU is not the root one would do thing on the remote. You should enumerate the users, then loop into users' personal settings sitting within the HKU and modify them. That's my opinion.

-tsuji
 
tsuji:

I have tried this and was unsuccessful. I may be do this wrong, but I could not enumerate the keys listed under HKU. This would be the prefered method since I could then modify all users which have previously logged in.

------------------------------------------------------------------------------
nobody knows everything about IT, so make a point to help your fellow members

-= j@ckle =-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top