Bianchi928
asked on
VBScript On Error
The following script works fine except that if the path that I want to copy to doesn't exist. I want to cater for this and write to the log file something like " PCName path not found" and carry on with the next entry in the input file
Thanks
Cheers
Dim objFSO, objFile, wmiQuery, objWMIService, objPing, objStatus
Set objShell = CreateObject("WScript.Shel l")
Set objWMIService = GetObject("winmgmts:\\.\ro ot\cimv2")
ComputersList = objShell.ExpandEnvironment Strings("% USERPROFIL E%") & "\Desktop\inputlist2.txt"
SourceFile = objShell.ExpandEnvironment Strings("% USERPROFIL E%") & "\Desktop\Interaction Training.url"
Const intForAppending = 8
ReportFile = objShell.ExpandEnvironment Strings("% USERPROFIL E%") & "\Desktop\outputlist2.txt"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objOutput = objFSO.OpenTextFile(Report File, intForAppending, False)
arrComputers = Split(objFSO.OpenTextFile( ComputersL ist).ReadA ll,vbNewLi ne)
For Each PC in arrComputers
username = "psr" & mid(pc,2,3) & "a"
Set objping = objWMIService.ExecQuery("S elect * From Win32_PingStatus Where " & "Address = '" & PC & "'")
for each objstatus in objping
If IsNull(objStatus.StatusCod e) Or objStatus.Statuscode <> 0 Then
ResolveIP = PC & " " & "Failed"
Else
objFSO.CopyFile SourceFile, "\\" & PC & "\C$\" & "Documents and Settings\" & username & "\desktop\"
ResolveIP = PC & " " & objStatus.ProtocolAddress & " Done"
End If
ObjOutput.WriteLine(resolv eip)
next
Next
objOutput.Close
Wscript.echo "Job Done"
Thanks
Cheers
Dim objFSO, objFile, wmiQuery, objWMIService, objPing, objStatus
Set objShell = CreateObject("WScript.Shel
Set objWMIService = GetObject("winmgmts:\\.\ro
ComputersList = objShell.ExpandEnvironment
SourceFile = objShell.ExpandEnvironment
Const intForAppending = 8
ReportFile = objShell.ExpandEnvironment
Set objFSO = CreateObject("Scripting.Fi
Set objOutput = objFSO.OpenTextFile(Report
arrComputers = Split(objFSO.OpenTextFile(
For Each PC in arrComputers
username = "psr" & mid(pc,2,3) & "a"
Set objping = objWMIService.ExecQuery("S
for each objstatus in objping
If IsNull(objStatus.StatusCod
ResolveIP = PC & " " & "Failed"
Else
objFSO.CopyFile SourceFile, "\\" & PC & "\C$\" & "Documents and Settings\" & username & "\desktop\"
ResolveIP = PC & " " & objStatus.ProtocolAddress & " Done"
End If
ObjOutput.WriteLine(resolv
next
Next
objOutput.Close
Wscript.echo "Job Done"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All good mate
Cheers
Cheers
When that isn't possible you have to do somethink like this:
on error resume next
<< code that might cause an error >>
If Err.Number <> 0 Then
'handle error here
End if