|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Get returned information from ping
I cannot get ping result by using the codes below:
Set objShell = Wscript.CreateObject("Wscript.Shell") objShell.Run "cmd /c ping -n 3 -w 1000 172.16.1.1 > Ping.inf", 0, True Can somebody tell me how to get the result? Thanks! You are redirecting the output to a text file called Ping.inf when you
use the > operator. Try opening it with notepad to see the result. Michael Reese Ofcourse I know, but nothing is in Ping.inf.
I use this one, but although there is "cmd /c ...", wscript still displays a CML window when running. I don't know why. CanPing = 0 Set objShell = WScript.CreateObject("WScript.Shell") Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 mail.cybersoft.vn > Ping.inf") Do While Not objExecObject.StdOut.AtEndOfStream strText = objExecObject.StdOut.ReadAll() If Instr(strText, "Reply") > 0 Then CanPing = 1 End If Loop Wscript.Echo "CanPing = " & CanPing ---------------------------------------------------------------------------------------------------------- Show quote "Michael Reese" <mnre***@hotmail.com> wrote in message news:1123126165.426229.101380@g43g2000cwa.googlegroups.com... > You are redirecting the output to a text file called Ping.inf when you > use the > operator. > > Try opening it with notepad to see the result. > > Michael Reese > Toan Do wrote:
Show quote > Ofcourse I know, but nothing is in Ping.inf. It is not possible to hide the console window the Exec method> I use this one, but although there is "cmd /c ...", wscript still displays a CML window when running. I don't know why. > > CanPing = 0 > Set objShell = WScript.CreateObject("WScript.Shell") > Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 mail.cybersoft.vn > Ping.inf") > Do While Not objExecObject.StdOut.AtEndOfStream > strText = objExecObject.StdOut.ReadAll() > If Instr(strText, "Reply") > 0 Then > CanPing = 1 > End If > Loop > > Wscript.Echo "CanPing = " & CanPing > Hi, creates. You might want to take a look at the IsConnectible function here and see if it works for you: http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/msg/0e17fd9e8ee66b35?dmode=source&hl=en -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx You might also look at using a freeware ping dll that can return the
information directly to the handler... I use dynu.dll - > http://www.dynu.com/dynuping.asp The examples listed on the site are ASP, but it's a matter of a couple keystrokes to convert it to native VBScript. Of course, it depends on how you intend to distribute the script. If you want to make the script portable, performing the stdout might be your only option. Rob "Toan Do" <toa***@cybersoft-vn.com> wrote in message Ofcourse I know, but nothing is in Ping.inf.news:emBInZKmFHA.3828@TK2MSFTNGP12.phx.gbl... I use this one, but although there is "cmd /c ...", wscript still displays a CML window when running. I don't know why. CanPing = 0 Set objShell = WScript.CreateObject("WScript.Shell") Set objExecObject = objShell.Exec("cmd /c ping -n 3 -w 1000 mail.cybersoft.vn > Ping.inf") Do While Not objExecObject.StdOut.AtEndOfStream strText = objExecObject.StdOut.ReadAll() If Instr(strText, "Reply") > 0 Then CanPing = 1 End If Loop Wscript.Echo "CanPing = " & CanPing ---------------------------------------------------------------------------------------------------------- Show quote "Michael Reese" <mnre***@hotmail.com> wrote in message news:1123126165.426229.101380@g43g2000cwa.googlegroups.com... > You are redirecting the output to a text file called Ping.inf when you > use the > operator. > > Try opening it with notepad to see the result. > > Michael Reese > I found out what is wrong. Everything is OK. That's my mistake.
But if I have a file name 'Ping.vbs' which contains some special codes, the ..vbs file in the same folder with Ping.vbs will run unexpectablly. Maybe a bug or something likes that of windows. hehe. Thanks for all comments. Toan Do wrote:
> I found out what is wrong. Everything is OK. That's my mistake. Not a bug, it is just how Windows works when you doesn't supply> But if I have a file name 'Ping.vbs' which contains some special > codes, the .vbs file in the same folder with Ping.vbs will run > unexpectablly. Maybe a bug or something likes that of windows. > hehe. > > Thanks for all comments. Hi, file extensions in your callouts and have the same base file names both in path and current directory. It is a good design rule to use full file name including file extension, and full path if possible as well. So your cmd /c ping -n 3 ... would work better like this: cmd.exe /c ping.exe -n 3 ... or better yet: %comspec% /c %SystemRoot%\System32\ping.exe -n 3 ... (%comspec% includes full path to cmd.exe) -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx You could use the WMI object for ping
strMachines = "172.25.1.202;172.25.1.204" aMachines = split(strMachines, ";") For Each machine in aMachines Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select * from Win32_PingStatus where address = '"_ & machine & "' AND ResolveAddressNames = TRUE") For Each objStatus in objPing 'Msgbox objStatus.ProtocolAddress Msgbox objStatus.ProtocolAddressResolved If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then tempo=objStatus.ProtocolAddressResolved End If Next Next Show quote "Toan Do" wrote: > I cannot get ping result by using the codes below: > > Set objShell = Wscript.CreateObject("Wscript.Shell") > objShell.Run "cmd /c ping -n 3 -w 1000 172.16.1.1 > Ping.inf", 0, True > > Can somebody tell me how to get the result? > Thanks! I believe that this only works for XP/2003, if I'm not mistaken...?
This would work if he doesn't have any pre-XP/2003 computers he is expecting to run it on. Otherwise, if not, this would be a great solution. Rob Show quote "usul" <u***@discussions.microsoft.com> wrote in message news:E111B7F1-AA0D-4C1B-A48F-3DEA576D65BB@microsoft.com... > You could use the WMI object for ping > > strMachines = "172.25.1.202;172.25.1.204" > aMachines = split(strMachines, ";") > > For Each machine in aMachines > Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ > ExecQuery("select * from Win32_PingStatus where address = '"_ > & machine & "' AND ResolveAddressNames = TRUE") > For Each objStatus in objPing > 'Msgbox objStatus.ProtocolAddress > Msgbox objStatus.ProtocolAddressResolved > If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then > tempo=objStatus.ProtocolAddressResolved > End If > Next > Next > > "Toan Do" wrote: > >> I cannot get ping result by using the codes below: >> >> Set objShell = Wscript.CreateObject("Wscript.Shell") >> objShell.Run "cmd /c ping -n 3 -w 1000 172.16.1.1 > Ping.inf", 0, True >> >> Can somebody tell me how to get the result? >> Thanks! Hi Toan Do
Here is the code I use to check wether hosts are online or not. As far as I can see it does'nt display any kind of window... It works well on W2K/XP. set oShell = createobject("wscript.shell") sCmd = "ping " & sAddress Set oExec = oShell.Exec(sCmd) do until oExec.StdOut.AtEndOfStream sOutput = trim(oExec.StdOut.ReadLine) if instr(ucase(sOutput),"TTL") Then isHostOnLine = true End if Loop HTh Florence Show quote "Toan Do" wrote: > I cannot get ping result by using the codes below: > > Set objShell = Wscript.CreateObject("Wscript.Shell") > objShell.Run "cmd /c ping -n 3 -w 1000 172.16.1.1 > Ping.inf", 0, True > > Can somebody tell me how to get the result? > Thanks! |
|||||||||||||||||||||||