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!

Modifying Reg Keys on remote computers 1

Status
Not open for further replies.

redlair

Technical User
Jun 29, 2004
54
0
0
US
I have a script I found and modified. I need it to stop the wuauserv service change some reg settings then start the service on a remote computer. The script stops/starts the remote service but does not change the remote computers reg settings. I have done some research on this but it is a little over my head. Can someone point me in the right direction.

-----------------------------------------------------------

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WNetwork = Wscript.CreateObject("Wscript.Network")
On Error Resume Next

'Query for target computer
strComputer = InputBox("Please enter the name of the computer you want to reset.", "Reset SUS Client Updates", WNetwork.ComputerName)
If strComputer = "" Then Wscript.Quit
strComputer = Ucase(strComputer)

'Stop the Automatic Updates service
Set oService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Service.Name='wuauserv'")
If Err = 462 Then
MsgBox "Computer " & strComputer & " does not exist.", 16, "Error"
Wscript.Quit
End If
If oService.StartMode = "Disabled" Then
MsgBox "The Automatic Updates service on " & strComputer & " is disabled." & vbCRLF & "No changes have been made.", 16, "Automatic Updates Error"
Wscript.Quit
Else
If oService.StartMode = "Manual" Then
Auto = MsgBox("The Automatic Updates service on " & strComputer & " is set to Manual." & vbCRLF & "Do you want to set it to Automatic?", 36, "Automatic Updates Service")
If Auto = vbYes Then oService.ChangeStartMode("Automatic")
End If
oService.StopService
End If

'Wait until the service stops
Do
Set oService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Service.Name='wuauserv'")
Loop Until oService.State = "Stopped"

'Reset the AUState to detect pending updates
WSHShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUState", 2, "REG_DWORD"


WshShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate", "0", "REG_DWORD"

'Force Automatic Updates

WSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\AUOptions", "4", "REG_DWORD"
WSHShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUOptions", "4", "REG_DWORD"

WSHShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\DetectionStartTime"
WSHShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\NextDetectionTime"
WSHShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallDate"
WSHShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallDay"
WSHShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ScheduledInstallTime"


'Delete the LastWaitTimeOut value if it exists
WSHShell.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\LastWaitTimeout"

'Start the Automatic Updates service
Set oService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Service.Name='wuauserv'")
oService.StartService

'Wait until the service starts
Do
Set oService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Service.Name='wuauserv'")
Loop Until oService.State = "Running"

MsgBox "Automatic Update reset is complete!" & vbCRLF & "The Automatic Update client on " & strComputer & " will begin the update detection process in approximately 10 minutes.", 64, "Automatic Updates
 
I see two possible ways to write to remote registries. I can either use a .REG or use a command line function.
 
I just take a look of your script and it is obvious that you should use stdregprov to change remote registry. using wshshell means all your changes take place on your local computer instead.

So take out all the regwrite regdelete etc and substitute instead something like this.
[tt]
const HKLM=&H80000002

Set oregService=GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:stdRegProv")

'Reset the AUState to detect pending updates
oregService.SetDWordValue HKLM, "Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "AUState", 2

oregService.SetDWordValue HKLM, "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU", "NoAutoUpdate", 0

'Force Automatic Updates
oregService.SetDWordValue HKLM, "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU", "AUOptions", 4
oregService.SetDWordValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "AUOptions", 4
oregService.DeleteValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "DetectionStartTime"
oregService.DeleteValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "NextDetectionTime"

oregService.DeleteValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "ScheduledInstallDate"

oregService.DeleteValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "ScheduledInstallDay"
oregService.DeleteValue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "ScheduledInstallTime"

'Delete the LastWaitTimeOut value if it exists
oregService.DeleteValue HKLM, "Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update", "LastWaitTimeout"

Set oregService=Nothing
[/tt]
I just edit out of your lines. Take a further look if there are typos. You get the idea.
 
Thank you, The reg settings worked great. What do I need to use if I want to add a message box or run a exe to a remote computer
 
If you run an administrative script against a remote computer, it is a _very_ bad idea to have an interactive part on the remote.

You can do a one-off thing like a pop out a message (that would hardly please the recepient), try shell out net send or use psexec (from sysinternals) to put a simple script to target m/c and run it. A no-brainer thing to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top