Announcement

Collapse
No announcement yet.

script to run on multiple workstations

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • script to run on multiple workstations

    Hi Guys,

    I'm pretty new to scripts.

    I have managed to get this script to run on 1 workstation , but I need it to run on about 70 in total.

    How would I get this to run say from a list.txt so I could add the workstation names into the list.
    Also how would go about logging which are successful and which have failed.

    Here's what I have

    Moderator edit: added code-tags around the batch
    Code:
    @echo off
    copy c:\msup.reg \\hostame\c$
    
    rem stop automatic updates service
    sc \\hostname stop wuauserv
    sleep 10
    rem delete registry entries
    psexec \\hostname regedit /s c:\msup.reg
    rem start automatic updates service
    sc \\hostname start wuauserv
    exit

    This is basically to resolve an issue with WSUS on the workstations.


    Thanks in advance
    Last edited by Rems; 2nd July 2009, 10:41.

  • #2
    Re: script to run on multiple workstations

    How about putting it in a GPO startup script so it runs on bootup
    You could add a line to echo the workstation name to a file on a network share to log the script running
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: script to run on multiple workstations

      That option would work but GP isnít managed by myself it's outsourced . It would properly take a 4 weeks to get it done with the amount of paper work and meetings they would want.

      Comment


      • #4
        Re: script to run on multiple workstations

        Using a computer startup script like Ossian suggested would be the easiest way.

        But if like to run the command remotely then you could use a for-do loop to go through the computernames from the list, to answer your question.
        sample:
        Code:
        @echo off
        
        For /f "usebackq" %%* in ("c:\computernames.txt") do (
          echo.%%*
          xcopy "c:\msup.reg" \\%%*\c$\
        
          rem stop automatic updates service
          sc \\%%* stop wuauserv
        
          rem delete registry entries
          psexec \\%%* regedit /s "c:\msup.reg"
        
          rem start automatic updates service
          sc \\hostname start wuauserv
        )
        
        pause
        I would be better thought to us more of the featurs of psexec.
        With a psexec command line you can copy a batch file and, it is able to read hostnames from a text file. Let psexec copy a batch (not just the reg file) to the computer and run that batch on the remote computer. Can you show what is in the reg file, maybe we can use reg.exe in the batch to do the registry edits.


        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: script to run on multiple workstations

          What are you trying to do with windows updates?

          Comment


          • #6
            Re: script to run on multiple workstations

            Hi Rems,

            Here's what is in the reg file


            Code:
             
             
            Windows Registry Editor Version 5.00
            [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate]
            "SusClientId"=-
            "AccountDomainSid"=-
            "PingID"=-

            Comment


            • #7
              Re: script to run on multiple workstations

              Originally posted by ekrengel View Post
              What are you trying to do with windows updates?
              I've been asked by our WSUS team to carry out the follwing. Apparently there is an issue with the workstations talking to the WSUS server.

              Code:
               
              1)First need to stop the Automatic Updates service.
              2)Second need to delete following entries from registry.
              
              "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" AccountDomainSid 
              "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" PingID 
              "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" SusClientId 
              
              3)Finallly need to startup the Automatic Updates service

              Comment


              • #8
                Re: script to run on multiple workstations

                I know exactly what you are trying to do, I had the same problem a couple months ago and created a vbscript to fix the issue. For us it was an issue with imaging where the SUS ID's didn't get re-created. Here was my solution:

                Code:
                Const HKLM = &H80000002
                
                'declared as global scopes in main script to be used with all procedures
                Dim objRegService, objShell
                
                ' list of comptuernames to read from
                strReadFile = "C:\dallas.txt"
                
                ' log file created with results
                strLogFile = "C:\log.txt"
                
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                Set objTS = objFSO.OpenTextFile(strReadFile)
                Set objFile = objFSO.OpenTextFile(strLogFile, 8)
                Set objShell = CreateObject("WScript.Shell")
                
                strService = "wuauserv"
                
                strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
                
                On Error Resume Next
                Do Until objTS.AtEndOfStream
                    strComputer = objTS.ReadLine
                		If (IsPingable(strComputer) = True) then
                			Set objWMIService = GetObject("winmgmts:" _
                    				& "{impersonationLevel=impersonate}!\\"_
                    				& strComputer & "\root\cimv2")
                			    If (Err.number = 0) Then
                				    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
                					For Each objItem In colItems
                						If (InStr(1,objItem.Caption, "XP", 1)) Then
                						    Set AutoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate",strComputer)
                						    Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
                						    Set objRegService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
                	 						& strComputer & "/root/default:stdRegProv")
                
                						        If RegKeyExists(HKLM, strRegKey, "IDDeleted") Then
                							     objFile.WriteLine strComputer & ": IDDEleted Exists!"
                
                    								'objRecordSet.MoveNext
                						        Else
                							     objregService.DeleteValue HKLM, strRegKey, "AccountDomainSid"
                							     objregService.DeleteValue HKLM, strRegKey, "PingID"
                							     objregService.DeleteValue HKLM, strRegKey, "SusClientId"
                
                        					     		If (objService.state = "Running" or objService.status = "OK") Then
                							    		objService.StopService()
                							    		objService.StartService()
                						     		End If
                
                						     		AutoUpdateClient.detectnow()
                
                						     		objregService.SetStringValue HKLM ,strRegKey ,"IDDeleted" ,"Yes"
                
                						     		objFile.WriteLine strComputer & ": fixed!"
                							End IF
                						Else
                							objFile.WriteLine strComputer & ": is not XP!"
                						End If
                					Next
                			    Else
                				   objFile.WriteLine strComputer & ": was not reachable through WMI!"
                			    End If
                			    Err.Clear
                		Else
                			objFile.WriteLine strComputer & ": was not pingable!"
                		End If
                
                	' Clean up
                	Set objWMIService = Nothing
                	Set colItems = Nothing
                	Set objService = Nothing
                	Set objRegService = Nothing
                	Set AutoUpdateClient = Nothing
                Loop
                
                Function IsPingable(ByVal strHost)
                  If Trim(strHost) <> "" Then
                     strCommand = "Ping.exe -n 3 -w 750 " & strHost
                     Set objExecObject = objShell.Exec _
                        ("%comspec% /c title " & strHost _
                        & chr(38) & strCommand)
                     Do While Not objExecObject.StdOut.AtEndOfStream
                        strText = objExecObject.StdOut.ReadLine()
                        If Instr(strText, "TTL=") > 0 _
                          Then IsPingable = True : Exit Do
                     Loop
                     If IsPingable = True then
                        With GetObject("winmgmts:root\cimv2")
                           For Each objProcess in .ExecQuery _
                              ("SELECT commandline FROM Win32_Process" _
                              & " WHERE Name = 'ping.exe'",,48)
                              If objProcess.commandline = strCommand _
                                Then objProcess.Terminate() : Exit For
                           Next
                        End With
                     End If
                  End If
                  If (not IsPingable = True) Then IsPingable = False
                End Function
                
                Function RegKeyExists(nHive, strPath, strValueName)
                	objregService.GetStringValue nHive, strPath, strValueName, strValue
                  	RegKeyExists = Not IsNull(strValue)
                End Function
                
                objFile.Close
                objTS.Close
                
                msgbox "done!"
                
                WScript.quit(0)

                Although I re-wrote the detection part a little while ago, I like this method better...instead of reading from a file this one will prompt you for the computer name you would like to run the script against. You can modify it to run like the script above.

                Code:
                'On Error Resume Next
                Const HKLM = &H80000002
                
                strComputer = Inputbox("Enter a computer name to fix WSUS updates","Invoke detectnow")
                	If strComputer = "" Then WScript.quit
                On Error Goto 0
                
                strService = "wuauserv"
                
                strExe = "cmd.exe /C rmdir %SystemRoot%\SoftwareDistribution /S /Q && %SystemRoot%\system32\wuauclt.exe /detectnow /resetauthorization"
                strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
                
                ' old method of forcing detection, it didn't have the feature to resetauth and is much slower
                ' Set AutoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate",strComputer)
                
                Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
                
                Set objRegService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
                	 & strComputer & "/root/default:stdRegProv")
                
                If RegKeyExists(HKLM, strRegKey, "IDDeleted") Then
                	msgbox "SusClientID has already been regenerated!"
                	WScript.quit
                Else
                	objregService.DeleteValue HKLM, strRegKey, "AccountDomainSid"
                	objregService.DeleteValue HKLM, strRegKey, "PingID"
                	objregService.DeleteValue HKLM, strRegKey, "SusClientId"
                
                        If (objService.state = "Running" or objService.status = "OK") Then
                		objService.StopService()
                		objService.StartService()
                	End If
                
                	Set objProcess = objWMIService.Get("Win32_Process")
                	Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
                		objProgram.CommandLine = strExe
                
                	Set strShell = objWMIService.ExecMethod( _
                		"Win32_Process", "Create", objProgram)
                	
                	' old method
                	' AutoUpdateClient.detectnow()
                
                	objregService.SetStringValue HKLM ,strRegKey ,"IDDeleted" ,"Yes"
                End If
                
                Function RegKeyExists( nHive, strPath, strValueName)
                	objregService.GetStringValue nHive, strPath, strValueName, strValue
                  	RegKeyExists = Not IsNull(strValue)
                End Function
                
                WScript.echo "Done!"
                WScript.quit(0)
                Last edited by ekrengel; 2nd July 2009, 13:02.

                Comment


                • #9
                  Re: script to run on multiple workstations

                  Here is a similar thread with script samples,
                  http://forums.petri.com/showthread.php?t=14469

                  A VBScript is a good choice also. The script can read the computer names from the list.
                  For batch or vbscript it is good to perform a ping test to check if the computer is connectable before trying to connect to it (like ekrengel also used in his sample). Keep a log of the comuters that were not able to contact.


                  \Rems

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: script to run on multiple workstations

                    Originally posted by ekrengel View Post
                    I know exactly what you are trying to do, I had the same problem a couple months ago and created a vbscript to fix the issue. For us it was an issue with imaging where the SUS ID's didn't get re-created. Here was my solution:

                    Code:
                    Const HKLM = &H80000002
                     
                    'declared as global scopes in main script to be used with all procedures
                    Dim objRegService, objShell
                     
                    ' list of comptuernames to read from
                    strReadFile = "C:\dallas.txt"
                     
                    ' log file created with results
                    strLogFile = "C:\log.txt"
                     
                    Set objFSO = CreateObject("Scripting.FileSystemObject")
                    Set objTS = objFSO.OpenTextFile(strReadFile)
                    Set objFile = objFSO.OpenTextFile(strLogFile, 8)
                    Set objShell = CreateObject("WScript.Shell")
                     
                    strService = "wuauserv"
                     
                    strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
                     
                    On Error Resume Next
                    Do Until objTS.AtEndOfStream
                        strComputer = objTS.ReadLine
                            If (IsPingable(strComputer) = True) then
                                Set objWMIService = GetObject("winmgmts:" _
                                        & "{impersonationLevel=impersonate}!\\"_
                                        & strComputer & "\root\cimv2")
                                    If (Err.number = 0) Then
                                        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
                                        For Each objItem In colItems
                                            If (InStr(1,objItem.Caption, "XP", 1)) Then
                                                Set AutoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate",strComputer)
                                                Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
                                                Set objRegService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
                                                 & strComputer & "/root/default:stdRegProv")
                     
                                                    If RegKeyExists(HKLM, strRegKey, "IDDeleted") Then
                                                     objFile.WriteLine strComputer & ": IDDEleted Exists!"
                     
                                                        'objRecordSet.MoveNext
                                                    Else
                                                     objregService.DeleteValue HKLM, strRegKey, "AccountDomainSid"
                                                     objregService.DeleteValue HKLM, strRegKey, "PingID"
                                                     objregService.DeleteValue HKLM, strRegKey, "SusClientId"
                     
                                                             If (objService.state = "Running" or objService.status = "OK") Then
                                                            objService.StopService()
                                                            objService.StartService()
                                                         End If
                     
                                                         AutoUpdateClient.detectnow()
                     
                                                         objregService.SetStringValue HKLM ,strRegKey ,"IDDeleted" ,"Yes"
                     
                                                         objFile.WriteLine strComputer & ": fixed!"
                                                End IF
                                            Else
                                                objFile.WriteLine strComputer & ": is not XP!"
                                            End If
                                        Next
                                    Else
                                       objFile.WriteLine strComputer & ": was not reachable through WMI!"
                                    End If
                                    Err.Clear
                            Else
                                objFile.WriteLine strComputer & ": was not pingable!"
                            End If
                     
                        ' Clean up
                        Set objWMIService = Nothing
                        Set colItems = Nothing
                        Set objService = Nothing
                        Set objRegService = Nothing
                        Set AutoUpdateClient = Nothing
                    Loop
                     
                    Function IsPingable(ByVal strHost)
                      If Trim(strHost) <> "" Then
                         strCommand = "Ping.exe -n 3 -w 750 " & strHost
                         Set objExecObject = objShell.Exec _
                            ("%comspec% /c title " & strHost _
                            & chr(38) & strCommand)
                         Do While Not objExecObject.StdOut.AtEndOfStream
                            strText = objExecObject.StdOut.ReadLine()
                            If Instr(strText, "TTL=") > 0 _
                              Then IsPingable = True : Exit Do
                         Loop
                         If IsPingable = True then
                            With GetObject("winmgmts:root\cimv2")
                               For Each objProcess in .ExecQuery _
                                  ("SELECT commandline FROM Win32_Process" _
                                  & " WHERE Name = 'ping.exe'",,48)
                                  If objProcess.commandline = strCommand _
                                    Then objProcess.Terminate() : Exit For
                               Next
                            End With
                         End If
                      End If
                      If (not IsPingable = True) Then IsPingable = False
                    End Function
                     
                    Function RegKeyExists(nHive, strPath, strValueName)
                        objregService.GetStringValue nHive, strPath, strValueName, strValue
                          RegKeyExists = Not IsNull(strValue)
                    End Function
                     
                    objFile.Close
                    objTS.Close
                     
                    msgbox "done!"
                     
                    WScript.quit(0)

                    Although I re-wrote the detection part a little while ago, I like this method better...instead of reading from a file this one will prompt you for the computer name you would like to run the script against. You can modify it to run like the script above.

                    Code:
                    'On Error Resume Next
                    Const HKLM = &H80000002
                     
                    strComputer = Inputbox("Enter a computer name to fix WSUS updates","Invoke detectnow")
                        If strComputer = "" Then WScript.quit
                    On Error Goto 0
                     
                    strService = "wuauserv"
                     
                    strExe = "cmd.exe /C rmdir %SystemRoot%\SoftwareDistribution /S /Q && %SystemRoot%\system32\wuauclt.exe /detectnow /resetauthorization"
                    strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
                     
                    ' old method of forcing detection, it didn't have the feature to resetauth
                    'Set AutoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate",strComputer)
                     
                    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                    Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
                     
                    Set objRegService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
                         & strComputer & "/root/default:stdRegProv")
                     
                    If RegKeyExists(HKLM, strRegKey, "IDDeleted") Then
                        msgbox "SusClientID has already been regenerated!"
                        WScript.quit
                    Else
                        objregService.DeleteValue HKLM, strRegKey, "AccountDomainSid"
                        objregService.DeleteValue HKLM, strRegKey, "PingID"
                        objregService.DeleteValue HKLM, strRegKey, "SusClientId"
                     
                            If (objService.state = "Running" or objService.status = "OK") Then
                            objService.StopService()
                            objService.StartService()
                        End If
                     
                        Set objProcess = objWMIService.Get("Win32_Process")
                        Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
                            objProgram.CommandLine = strExe
                     
                        Set strShell = objWMIService.ExecMethod( _
                            "Win32_Process", "Create", objProgram)
                     
                        ' old method
                        'AutoUpdateClient.detectnow()
                     
                        objregService.SetStringValue HKLM ,strRegKey ,"IDDeleted" ,"Yes"
                    End If
                     
                    Function RegKeyExists( nHive, strPath, strValueName)
                        objregService.GetStringValue nHive, strPath, strValueName, strValue
                          RegKeyExists = Not IsNull(strValue)
                    End Function
                     
                    WScript.echo "Done!"
                    WScript.quit(0)

                    I've copied the text from your first script into notepad and renamed to .vbs .
                    Now here's the stupid question how to I run it.
                    By the way VB is like chinease to me only now learning basic batch files.

                    Comment


                    • #11
                      Re: script to run on multiple workstations

                      Create a txt file on the root of C: with all the computer names you would like to run the script against (1 line at a time with no spaces after the computername, or else it doesn't get read properly). Then replace this line in the script with the name of the txt file you created:

                      Code:
                      strReadFile = "C:\dallas.txt"
                      So if you named it computername.txt, then it would be

                      Code:
                      strReadFile = "C:\computername.txt"
                      The double click the vbscript file and let it run. You will see command line boxes pop up, and then should let you know it's working. When it's done you will get a msg box saying "Done!"

                      Also, you can check the log file to make sure its running properly too. It will get created automatically on the root of C: as well (log.txt), you can rename that as well if you like. I really recommend using the other method though with spawning a process, it's much faster. Since you dont' have too many computer though it might not be that bad...but let me know how it works out.

                      Comment


                      • #12
                        Re: script to run on multiple workstations

                        That's what I did. Which I think was more luck than judgment.



                        I get an error when I run the vb

                        Script: C\Msupdates.vbs
                        Line 14
                        Char 1
                        Error file not found
                        Code 800A0035
                        Source Microsoft VBScript runtime error

                        hope this helps

                        Comment


                        • #13
                          Re: script to run on multiple workstations

                          Oops sorry! The log file doesn't get created automatically. I made the changes...and also modified the script for you with the new method. Again make sure you put the right txt file name in there for the computers.

                          EDIT** I put in comments in the script to help you better understand what's going on

                          Code:
                          ' hkey local machine constant value
                          Const HKLM = &H80000002
                          
                          ' declared as global scopes in main script to be used with all procedures
                          Dim objRegService, objShell
                          
                          ' name file to read from
                          strReadFile = "C:\computers.txt"
                          ' name of log file to create
                          strLogFile = "C:\log.txt"
                          Set objFSO = CreateObject("Scripting.FileSystemObject")
                          
                          ' open the computer name txt file to read from
                          Set objTS = objFSO.OpenTextFile(strReadFile)
                          ' create the log file
                          Set objFile = objFSO.CreateTextFile(strLogFile, 8)
                          Set objShell = CreateObject("WScript.Shell")
                          
                          ' name of windows update service
                          strService = "wuauserv"
                          
                          ' command to detect and reset auth
                          strExe = "cmd.exe /C rmdir %SystemRoot%\SoftwareDistribution /S /Q && %SystemRoot%\system32\wuauclt.exe /detectnow /resetauthorization"
                          
                          ' path of windows update reg keys
                          strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate"
                          
                          On Error Resume Next
                          ' read computer name file until the end
                          Do Until objTS.AtEndOfStream
                              strComputer = objTS.ReadLine
                          
                          		' if computer is pingable, the move onto next line
                          		If (IsPingable(strComputer) = True) then
                          			Set objWMIService = GetObject("winmgmts:" _
                              				& "{impersonationLevel=impersonate}!\\"_
                              				& strComputer & "\root\cimv2")
                          
                          			    ' if no error connection with WMI, then continue
                          			    If (Err.number = 0) Then
                          				    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
                          					For Each objItem In colItems
                          
                          						' if computer is not XP, then move onto next name in file
                          						If (InStr(1,objItem.Caption, "XP", 1)) Then
                          							Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
                          							Set objRegService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" _
                          	 							& strComputer & "/root/default:stdRegProv")
                          
                          							' check if script has already ran against current computer
                          						        If RegKeyExists(HKLM, strRegKey, "IDDeleted") Then
                          							     objFile.WriteLine strComputer & ": IDDEleted Exists!"
                          						        Else
                          
                          							     ' delete reg keys
                          							     objregService.DeleteValue HKLM, strRegKey, "AccountDomainSid"
                          							     objregService.DeleteValue HKLM, strRegKey, "PingID"
                          							     objregService.DeleteValue HKLM, strRegKey, "SusClientId"
                          								' stop and start windows update service
                                  					     		If (objService.state = "Running" or objService.status = "OK") Then
                          							    		objService.StopService()
                          							    		objService.StartService()
                          						     		End If
                          								
                          								' spawn process on remote machine to detect auth
                          								Set objProcess = objWMIService.Get("Win32_Process")
                          								Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
                          									objProgram.CommandLine = strExe
                          
                          								Set strShell = objWMIService.ExecMethod( _
                          									"Win32_Process", "Create", objProgram)
                          
                          								' create reg key to document that script has ran on current computer
                          						     		objregService.SetStringValue HKLM ,strRegKey ,"IDDeleted" ,"Yes"
                          
                          						     		objFile.WriteLine strComputer & ": fixed!"
                          							End IF
                          						Else
                          							objFile.WriteLine strComputer & ": is not XP!"
                          						End If
                          					Next
                          			    Else
                          				   objFile.WriteLine strComputer & ": was not reachable through WMI!"
                          			    End If
                          			    Err.Clear
                          		Else
                          			objFile.WriteLine strComputer & ": was not pingable!"
                          		End If
                          
                          	' Clean up
                          	Set objWMIService = Nothing
                          	Set colItems = Nothing
                          	Set objService = Nothing
                          	Set objRegService = Nothing
                          Loop
                          
                          Function IsPingable(ByVal strHost)
                            If Trim(strHost) <> "" Then
                               strCommand = "Ping.exe -n 3 -w 750 " & strHost
                               Set objExecObject = objShell.Exec _
                                  ("%comspec% /c title " & strHost _
                                  & chr(38) & strCommand)
                               Do While Not objExecObject.StdOut.AtEndOfStream
                                  strText = objExecObject.StdOut.ReadLine()
                                  If Instr(strText, "TTL=") > 0 _
                                    Then IsPingable = True : Exit Do
                               Loop
                               If IsPingable = True then
                                  With GetObject("winmgmts:root\cimv2")
                                     For Each objProcess in .ExecQuery _
                                        ("SELECT commandline FROM Win32_Process" _
                                        & " WHERE Name = 'ping.exe'",,48)
                                        If objProcess.commandline = strCommand _
                                          Then objProcess.Terminate() : Exit For
                                     Next
                                  End With
                               End If
                            End If
                            If (not IsPingable = True) Then IsPingable = False
                          End Function
                          
                          Function RegKeyExists(nHive, strPath, strValueName)
                          	objregService.GetStringValue nHive, strPath, strValueName, strValue
                            	RegKeyExists = Not IsNull(strValue)
                          End Function
                          
                          objFile.Close
                          objTS.Close
                          
                          msgbox "done!"
                          
                          WScript.quit(0)
                          Last edited by ekrengel; 2nd July 2009, 13:54. Reason: Added comments for better explanation of what script is doing

                          Comment


                          • #14
                            Re: script to run on multiple workstations

                            Thank you very much for your help on this. I think this has hooked me on learning VB.

                            Just to confrim does the script stop automatic update service and restart after the registry keys have been deleted.

                            Comment


                            • #15
                              Re: script to run on multiple workstations

                              No problem

                              I got hooked to vbscript as well, mostly from all the help that I got here on this forum. Everyone is always here to help.

                              And yes, the script does stop and start the service after the keys have been deleted. It then adds the "IDDeleted" key so the next time you run the script, it will recognized that it has already ran on that machine, and will skip it. I found that I had to run the script multiple times because some machines were turned off.

                              Comment

                              Working...
                              X