jmoody
asked on
VBS to ping an IP and display the results
I need to write a vbs script to ping an IP address 10 times and then display the results. I would like results displayed similar to how they display at the command line with the replies and time or even if it opened the command prompt that would be good.
Do you want that in a pop-up window or written to a text file?
Oh, does it have to be vbscript, or will a batch file work?
ASKER
it can be either pop up or written to a text file. has to be vbscript because the image this is going on blocks batch files.
Ok, no problem. Give me another 20 minutes, need coffee.... :-)
ASKER
thanks
Ok, I took in to account that you will want to change this to meet your needs, but here is a log file version. These are great because the log file can be referenced later.
There is a self destruct line in the file that is commented out, if you want to use it, just remove the (') in front of the line.
You can easily edit this in notepad, or if you want a good and inexpensive VBS editor, download and try out VbsEdit: http://www.vbsedit.com/
The demo is free with no timeout, just a nag screen, but if you purchase watch for a sale. I got my copy for $49.99!
Change the IP and the log file location and/or name as needed.
Have fun!
on error resume next
dim wshShell
dim path
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
WShShell.run "ping -n 10 127.0.0.1 >>C:\Temp\ping.txt", hidden
''' wscript self destruct and exit command: un-comment the line below to have the script delete itself after running.
'fso.GetFile(WScript.scriptfullname).delete
wscript.quit
There is a self destruct line in the file that is commented out, if you want to use it, just remove the (') in front of the line.
You can easily edit this in notepad, or if you want a good and inexpensive VBS editor, download and try out VbsEdit: http://www.vbsedit.com/
The demo is free with no timeout, just a nag screen, but if you purchase watch for a sale. I got my copy for $49.99!
Change the IP and the log file location and/or name as needed.
Have fun!
ASKER
Sorry, I am not very good with vbscript yet. It does not create the text file and how can I have the script open the text file once it is finished.
No problem, it may be an issue with permissions to that folder. What is the path you want the log file to save to? Make sure you can create a new text file and then edit that file in that location.
I'll add a line to open the file as well.
I'll add a line to open the file as well.
ASKER
That location is fine. I can create a file in C:\Temp, edit it and delete it so I don't think it is a permissions issue.
Ok, just add a line under the existing command, so that it looks like this:
WShShell.run "ping -n 10 127.0.0.1 >>C:\Temp\ping.txt", hidden
WShShell.Run "notepad.exe C:\Temp\ping.txt"
It may be that you AV, security settings, or GPO is blocking a vbscript from running in or against the C:\temp folder. I find that on a lot of sites where I do consulting work.
If this is running on XP, try this:
WShShell.run "ping -n 10 127.0.0.1 >>%UserProfile%\My Documents\ping.txt", hidden
WShShell.Run "notepad.exe %UserProfile%\My Documents\ping.txt"
If this is running on Vista or 7, try this:
WShShell.run "ping -n 10 127.0.0.1 >>%userprofile%\documents\ ping.txt", hidden
WShShell.Run "notepad.exe %userprofile%\documents\pi ng.txt"
WShShell.run "ping -n 10 127.0.0.1 >>C:\Temp\ping.txt", hidden
WShShell.Run "notepad.exe C:\Temp\ping.txt"
It may be that you AV, security settings, or GPO is blocking a vbscript from running in or against the C:\temp folder. I find that on a lot of sites where I do consulting work.
If this is running on XP, try this:
WShShell.run "ping -n 10 127.0.0.1 >>%UserProfile%\My Documents\ping.txt", hidden
WShShell.Run "notepad.exe %UserProfile%\My Documents\ping.txt"
If this is running on Vista or 7, try this:
WShShell.run "ping -n 10 127.0.0.1 >>%userprofile%\documents\
WShShell.Run "notepad.exe %userprofile%\documents\pi
ASKER
It opens notepad the file still does not get created. I'm not sure if the ping command is being run.
Ok, which OS?
I'll add some echo commands to step you through then you can comment or delete them when it is working.
Which directories did you try?
What AV is running? - We may need to add an exception for the process and/or folder.
I'll add some echo commands to step you through then you can comment or delete them when it is working.
Which directories did you try?
What AV is running? - We may need to add an exception for the process and/or folder.
ASKER
Win XP. I tried C:\temp, My Documents and and flash drive. I have McAfee.
Interesting, I have this running on WinXP with McAfee as well.
Try this,
This will get ride of the hidden part so that you can see the command prompt come up and start the ping. I tested as WScript and CScript as the default engine and it pops the command prompt up and pings the loop back with no problem.
If this works, then edit it to ping the IP or host name you will be using and try again.
Try this,
On error resume next
dim wshShell
dim path
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
WShShell.run "ping -n 10 127.0.0.1"
''' wscript self destruct and exit command: un-comment the line below to have the script delete itself after running.
'fso.GetFile(WScript.scriptfullname).delete
wscript.quit
This will get ride of the hidden part so that you can see the command prompt come up and start the ping. I tested as WScript and CScript as the default engine and it pops the command prompt up and pings the loop back with no problem.
If this works, then edit it to ping the IP or host name you will be using and try again.
ASKER
I can see the command prompt and it pings with no problem.
Ok, great! Then that means that something is preventing vbs from creating the log file.
Save the script to an area that is already in the exclusions list, then change the log file location to write there as well.
So to find excluded locations, open regedit and got to this key:
HKEY_LOCAL_MACHINE\SOFTWAR E\McAfee\V SCore\On Access Scanner\McShield\Configura tion\Defau lt
Look for values like:
Value 31
Name: ExcludedItem_10
Type: REG_SZ
Data: 3|15|c:\program files\Blah_blah
Value 32
Name: ExcludedItem_11
Type: REG_SZ
Data: 3|15|D:\Data\scripts\
These are safe zones. You may want to have an exception created for your image tools. I was an ePO admin, so I just added C:\sysprep\ and C:\sysprep\tools to my exception list for the container that my image machines were in.
I then put a ton of batch files, scripts, and other tools in that folder so I could get the images the way they needed to be prior to running sysperp and taking an image.
Remember to kill the McAfee GUID before running sysprep and taking a snapshot! Your ePO admin will be mad if you deploy 200 desktops that all check in as the same machine. :-)
Save the script to an area that is already in the exclusions list, then change the log file location to write there as well.
So to find excluded locations, open regedit and got to this key:
HKEY_LOCAL_MACHINE\SOFTWAR
Look for values like:
Value 31
Name: ExcludedItem_10
Type: REG_SZ
Data: 3|15|c:\program files\Blah_blah
Value 32
Name: ExcludedItem_11
Type: REG_SZ
Data: 3|15|D:\Data\scripts\
These are safe zones. You may want to have an exception created for your image tools. I was an ePO admin, so I just added C:\sysprep\ and C:\sysprep\tools to my exception list for the container that my image machines were in.
I then put a ton of batch files, scripts, and other tools in that folder so I could get the images the way they needed to be prior to running sysperp and taking an image.
Remember to kill the McAfee GUID before running sysprep and taking a snapshot! Your ePO admin will be mad if you deploy 200 desktops that all check in as the same machine. :-)
ASKER
I found one ExcludedItem_5 3|15|C:\Utilities and I changed the path to the c:\utilities and I have the same problem. The screen just flashed and the file does not get created. I'm not sure what is going on. If I take the redirection to the text file out the command propmt comes up and then closes. Is there a way to keep it open? It there is that might be good enough.
Make sure that you are running the script from there as well. McAfee may kill the process because it is not running from the C:\Utilities folder.
In the mean time, I'll see what I can do about pausing after the command completes.
In the mean time, I'll see what I can do about pausing after the command completes.
Did running the script from the "C:\Utilities" folder fix the issue?
ASKER
No that did not help. Thanks for checking.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the dealy. I was on vacation. This is working in the comptuers without any problems. What are commented parts?
The script will accept input from a commadn line or batch file,so you can pas the hostname or IP address to it like tis:
multiping.vbs 127.0.0.1
Probably not much good for you since batch files are blocked. Glad that it worked for you!
multiping.vbs 127.0.0.1
Probably not much good for you since batch files are blocked. Glad that it worked for you!
ASKER
Thanks for your help,