Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello community,

I have a script I created that has a msg box for computer name entry and then pings, if OK it continues with the script which checks for network drive, map drive, copies file to computer and then runs psexec on the remote PC with the copied file, puts entry in remopte computer event viewer and then removes drive mapping.

How can I change the script to use a list of computers, out put a list of computers that are not online but continue with my script,mapping drive,copying file, run psexec,entry in event viewer,unmap drive and log a success??

I am super new to any kinf od scripting so any help and explanation of the method would really really help,

many thanks

Heres the code that I just about got working

VB



'setting objects
Dim net, objFSO, shell
Dim objFile, strLine, intResult
Set objnet = CreateObject("wscript.network")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objshell = CreateObject("wscript.shell")
strfile = "c:\wuafix\wuafix.vbs"
strUser = "domain\user"
strPassword = "password"

'getting server name or IP address
strComputer=InputBox("Enter the IP or computer name of the remote machine on which to repair the WUA agent:", "Starting WUA Fix")

'check to see if the server can be reached
Dim strPingResults
Set pingExec = objshell.Exec("ping -n 3 -w 2000 " & strComputer) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(pingExec.StdOut.ReadAll)
If Not InStr(strPingResults, "reply from")>0 Then
WScript.Echo strComputer & " did not respond to ping."
WScript.Quit
End If

'Check if source file exists
If Not objFSO.FileExists(strFile) Then
WScript.Echo "The source file does not exist"
WScript.Quit
End If

MsgBox "The WUA Fix is in process. Please wait.", 64, "Script Message"

'mapping drive to remote machine
If objFSO.DriveExists("Z:") Then
objnet.RemoveNetworkDrive "Z:","True","True"
End If

objnet.MapNetworkDrive "Z:", "\\" & strComputer & "\c$", True

'creating folder for install exe on remote machine
If (objFSO.FolderExists("Z:\wuafix\") = False) Then
objFSO.CreateFolder "Z:\wuafix"
End If

'copying vbs to remote machine
objFSO.CopyFile strFile, "Z:\wuafix\wuafix.vbs"
'set command line executable to run a silent install remotely
strInstaller1 = "cscript.exe c:\wuafix\wuafix.vbs"
'strInstaller2 = "c:\wuafix\wuafix.vbs"
strExec = "c:\pstools\PsExec.exe "


'objshell.Run strExec & " \\" & strComputer & strInstaller1
On Error Resume Next
result = objshell.Run(strExec & " \\" & strComputer & " " & strInstaller1)
If Err.Number = 0 Then
WScript.Echo "PSXEC Runing WUA fix remotely"
Else MsgBox Err.Number
MsgBox result
End If

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Application' AND " _
& "EventCode = '4'")
Wscript.Echo "Event Viewer checked and Fix Applied:" & colLoggedEvents.Count

MsgBox "Removing mapped drive Please wait.", 64, "Script Message"

If objFSO.DriveExists("Z:") Then
objnet.RemoveNetworkDrive "Z:","True","True"
End If
MsgBox "The WUA Fix has been applied.", 64, "Script Message"
quit
wscript.quit
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900