The system cannot find the file specified. Error 80070002 Source:  WshShell.exe


Hi

I am new to VBscript, trying to run below script to ping machine reading input file and ping result should be in stored in lower case based on if the machine is online of offline. However when running the file getting error"The system cannot find the file specified." on line "Objshell.Exec("ping"&strcomputer)"

Any idea why it is showing this error please

Regards,
Madhan



Setfso=CreateObject("Scripting.Filesystemobject")
Setobjshell=CreateObject("WScript.shell")
SetobjInputFile=fso.OpenTextFile("D:\Madhan\Learning\VBScript\Logs\Computers.log",1,True)
SetobjOutputFile=fso.OpenTextFile("D:\Madhan\Learning\VBScript\Logs\Results.log",2,True)
DoWhileobjinputFile.AtEndOfLine<>True
strComputer=objInputFile.ReadLine
SetobjScriptExec=Objshell.Exec("ping"&strcomputer)
strPingResults=LCase(objScriptExec.StdOut.ReadAll)
WScript.EchostrPingResults
IfInStr(strPingResults,"replyfrom")Then
WScript.Echo"Themachineisup!"
Else
WScript.Echo"TheMachineiddown!"
EndIf
Loop





June 20th, 2015 12:10pm

When you add this debug line then you will see straight away that you need a space after "ping":

wscript.echo "ping"& strcomputer
Set
objScriptExec=Objshell.Exec("ping"& strcomputer)

You are also likely to experience problems with the Exec function because it might still run in the background while your script continues. I prefer to use the Run function, getting it to write its output to a temp file and forcing it to wait until ping.exe has completed its job.

Lastly: Checking the screen output from ping.exe for the existence of the string "reply from" is unreliable because in some cases you can get the response you see below. It's much safer to test for the string "bytes=".

Pinging 192.168.111.201 with 32 bytes of data:
Reply from 192.168.111.200: Destination host unreachable.
Reply from 192.168.111.200: Destination host unreachable.

Free Windows Admin Tool Kit Click here and download it now
June 20th, 2015 12:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics