Login | |
|
 |
Re: Redirect a Ping command to a log or text file? - 6/8/2005 7:42:59 AM
|
|
 |
|
| |
mbouchard
Posts: 1922
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
The easist way to do that would be to use cmd prompt redirector. intCMD = objShell.Run("cmd /c ping " & strServer & " >c:\" & strServer & "_PING.txt",1,TRUE) Do a search and look for a ping post that I did, it is more involved but may have what you are looking for.
|
|
| |
|
|
|
 |
Re: Redirect a Ping command to a log or text file? - 6/13/2005 3:02:59 AM
|
|
 |
|
| |
Country73
Posts: 735
Score: 10
Status: offline
|
This is what I use for any script that I generally have to run against multiple machines. (Basically my "Script Template") This will also create a countdown for machines remaining. Very handy when needing to run a lengthy script against 2000+ machines. Set oFS = CreateObject("Scripting.FileSystemObject") Set wshShell = WScript.CreateObject("WScript.Shell") Const strScript = "Script Template" Const PCL = "pclist.txt" Const OFF = "offline.txt" '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' Force script to run in "CScript" mode '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then Set shell = CreateObject("WScript.Shell") shell.Run "cscript """ & WScript.ScriptFullName & """", 1, False WScript.Quit End If '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' User input to determine if script is ran against single or multiple machines. strComputer = InputBox("Which machine do you wish to run this script against?" & vbcrlf _ & vbcrlf & "Leave blank to run against " & chr(34) & "pclist.txt" & chr(34),strScript,"") If strComputer = "" Then If oFS.FileExists(PCL)Then '-Gets a count for machines to run against- Set file = oFS.GetFile(PCL) Set pc = file.OpenAsTextStream(1,TristateUseDefault) Do While pc.AtEndOfStream <> True strComputer = Trim(pc.ReadLine) strCount = strCount + 1 Loop '-Pull netbios to run script against- Set pc = file.OpenAsTextStream(1,TristateUseDefault) Do While pc.AtEndOfStream <> True strComputer = Trim(pc.ReadLine) strCount = strCount - 1 wscript.echo strCount & " " & strComputer Call PingMe(strComputer,strCount) Loop Else wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close." wscript.quit End If Else strCount = "" Call PingMe(strComputer,strCount) End If wscript.echo "Finished" 'Functions '------------------------------------------------------------------------------ Function PingMe(strComputer,strCount)'-Check to make sure machine is online first Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'") For Each oPingResult In cPingResults If oPingResult.StatusCode = 0 Then wscript.echo "call function required" Else call LogEvent(strComputer,"Offline") End If Next End Function '+++++++++++++++++++OFFLINE+++++++++++++++++++++++ Function LogEvent(pc,msg)'If OFFLINE, create a log Set strLogFile = oFS.OpenTextFile(OFF,8,True) strLogFile.WriteLine pc & vbTab & msg strLogFile.Close End Function '+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|