VB Script that needs to read from a text file - vbscript

I have a VB Script that goes out to a string of servers and checks to see if there are any pending Windows updates. It works perfectly. The only issue is to run the script I have to type:
cscript pending.vbs server01 server02 server03 server04 etc.. I have over 300 servers I want to run this against. I need to be able to update a text file with server names instead of manually typing them out. I am posting the script below:
I am not a programmer by far, but I do understand some.
Thanks!
'#
'# ServerPendingUpdates.vbs
'#
'# Usage: cscript ServerPendingUpdates.vbs {servername} {servername} {servername} {servername}
'# If no {servername} specified then 'localhost' assumed
'#
'# To do: Error handling
'#
Option Explicit
Dim strServer : strServer = GetArgValue(0,"localhost")
'#
'# Loop through the input parameters for each server
'#
Dim i
For i = 0 To WScript.Arguments.Count - 1
CheckServerUpdateStatus GetArgValue(i,"localhost") 'strServer
Next
WScript.Quit(0)
Function CheckServerUpdateStatus( ByVal strServer )
WScript.Echo vbCRLF & "Connecting to " & strServer & " to check software update status..."
Dim blnRebootRequired : blnRebootRequired = False
Dim blnRebootPending : blnRebootPending = False
Dim objSession : Set objSession = CreateObject("Microsoft.Update.Session", strServer)
Dim objUpdateSearcher : Set objUpdateSearcher = objSession.CreateUpdateSearcher
Dim objSearchResult : Set objSearchResult = objUpdateSearcher.Search(" IsAssigned=1 and IsHidden=0 and Type='Software'")
'#
'#
'#
Dim i, objUpdate
Dim intPendingInstalls : intPendingInstalls = 0
For i = 0 To objSearchResult.Updates.Count-1
Set objUpdate = objSearchResult.Updates.Item(I)
If objUpdate.IsInstalled Then
If objUpdate.RebootRequired Then
blnRebootPending = True
End If
Else
intPendingInstalls = intPendingInstalls + 1
'If objUpdate.RebootRequired Then '### This property is FALSE before installation and only set to TRUE after installation to indicate that this patch forced a reboot.
If objUpdate.InstallationBehavior.RebootBehavior <> 0 Then
'# http://msdn.microsoft.com/en-us/library/aa386064%28v=VS.85%29.aspx
'# InstallationBehavior.RebootBehavior = 0 Never reboot
'# InstallationBehavior.RebootBehavior = 1 Must reboot
'# InstallationBehavior.RebootBehavior = 2 Can request reboot
blnRebootRequired = True
End If
End If
Next
WScript.Echo strServer & " has " & intPendingInstalls & " updates pending installation"
If blnRebootRequired Then
WScript.Echo strServer & " WILL need to be rebooted to complete the installation of these updates."
Else
WScript.Echo strServer & " WILL NOT require a reboot to install these updates."
End If
'#
'#
'#
If blnRebootPending Then
WScript.Echo strServer & " is waiting for a REBOOT to complete a previous installation."
End If
End Function
'#
'#
'#
Function GetArgValue( intArgItem, strDefault )
If WScript.Arguments.Count > intArgItem Then
GetArgValue = WScript.Arguments.Item(intArgItem)
Else
GetArgValue = strDefault
End If
End Function

You can query all domain using an ASDI object in vbs:
Set DomObj = GetObject("WinNT://" & strDomain )
DomObj.Filter = Array("computer")
Will output an array (DomObj)
or use LDAP:
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
strQuery = "<LDAP://" & strDNSDomain & "> (objectCategory=computer);distinguishedName,operatingSystem;subtree"
Source:
http://www.scriptlook.com/list-servers-domain/ &
http://www.scriptlook.com/check-services-every-server-domain/

Just create a text file with the list of servers, one per line.
Open the file (OpenTextFile) and read it line by line. See these links for reference
http://ss64.com/vb/filesystemobject.html
FileSystemObject Object
path = "serverlist.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(path, 1)
Do Until objFile.AtEndOfStream
CheckServerUpdateStatus(objFile.ReadLine)
Loop

Related

Vbscript Copy List of Folders to FTP Server

Hi I have the following script
Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Path to file or folder to upload
Source0 = "C:\Users\User\Desktop\Work\CRC01\8BR01547\61000856"
FTPUpload(Source0)
Sub FTPUpload(Source0)
On Error Resume Next
'Copy Options: 16 = Yes to All
Const copyType = 16
'FTP Wait Time in ms
waitTime = 80000
FTPUser = "Martin"
FTPPass = ""
FTPHost = "PC247"
FTPDir0 = "/Martin/61000856"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "#" & FTPHost & FTPDir0
Set objFTP = oShell.NameSpace(strFTP)
'Make new folder on FTP site
'objFTP.NewFolder "FTP Backup"
'Upload single file
If objFSO.FileExists(Source0) Then
Set objFile = objFSO.getFile(Source0)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)
Set objItem = objFolder.ParseName(objFile.Name)
Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
objFTP.CopyHere objItem, copyType
End If
'Upload all files in folder
If objFSO.FolderExists(Source0) Then
'Code below can be used to upload entire folder
Set objFolder = oShell.NameSpace(Source0)
Wscript.Echo "Uploading folder " & Source0 & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType
End If
If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If
'Wait for upload
WScript.Sleep waitTime
End Sub
Could someone please help on how to make it so that I can provide a list of sources and it copys the folders over to the FTP server. Also How to I fix the overwrite confirmation popup that still happens even if the copytype is set too 16

Upload and download a file using FTP without ActiveX

I want VBScript to upload and download a file using FTP without using ActiveX program.
Notice please give me download code alone and upload code alone and must upload file not folder.
For example:
Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
path = "test.txt"
FTPUpload(path)
Sub FTPUpload(path)
On Error Resume Next
Const copyType = 16
waitTime = 80000
FTPUser = "user"
FTPPass = "pass"
FTPHost = "www.domain.com"
FTPDir = "/htdocs/"
strFTP = "ftp://" & FTPUser & ":" & FTPPass & "#" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)
'objFTP.NewFolder "FTP Backup"
If objFSO.FileExists(path) Then
Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)
Set objItem = objFolder.ParseName(objFile.Name)
Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
objFTP.CopyHere objItem, copyType
End If
If objFSO.FolderExists(path) Then
Set objFolder = oShell.NameSpace(path)
Wscript.Echo "Uploading folder " & path & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType
End If
If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If
WScript.Sleep waitTime
End Sub

vbscript code to read input from text file avoiding manual efforts

I am drilling down Internet to get Vbscript code, where input is read from text file one per line and pass it to the commands in script. I am just a beginner and need help with this.
Basically I am gathering script to get pending patches of servers in our environment. The script looks like below:
'#
'# ServerPendingUpdates.vbs
'#
'# Usage: cscript ServerPendingUpdates.vbs {servername} {servername} {servername} {servername}
'# If no {servername} specified then 'localhost' assumed
'#
'# To do: Error handling
'#
Option Explicit
Dim strServer : strServer = GetArgValue(0,"localhost")
'#
'# Loop through the input parameters for each server
'#
Dim i
For i = 0 To WScript.Arguments.Count - 1
CheckServerUpdateStatus GetArgValue(i,"localhost") 'strServer
Next
WScript.Quit(0)
Function CheckServerUpdateStatus( ByVal strServer )
WScript.Echo vbCRLF & "Connecting to " & strServer & " to check software update status..."
Dim blnRebootRequired : blnRebootRequired = False
Dim blnRebootPending : blnRebootPending = False
Dim objSession : Set objSession = CreateObject("Microsoft.Update.Session", strServer)
Dim objUpdateSearcher : Set objUpdateSearcher = objSession.CreateUpdateSearcher
Dim objSearchResult : Set objSearchResult = objUpdateSearcher.Search(" IsAssigned=1 and IsHidden=0 and Type='Software'")
'#
'#
'#
Dim i, objUpdate
Dim intPendingInstalls : intPendingInstalls = 0
For i = 0 To objSearchResult.Updates.Count-1
Set objUpdate = objSearchResult.Updates.Item(I)
If objUpdate.IsInstalled Then
If objUpdate.RebootRequired Then
blnRebootPending = True
End If
Else
intPendingInstalls = intPendingInstalls + 1
'If objUpdate.RebootRequired Then '### This property is FALSE before installation and only set to TRUE after installation to indicate that this patch forced a reboot.
If objUpdate.InstallationBehavior.RebootBehavior <> 0 Then
'# http://msdn.microsoft.com/en-us/library/aa386064%28v=VS.85%29.aspx
'# InstallationBehavior.RebootBehavior = 0 Never reboot
'# InstallationBehavior.RebootBehavior = 1 Must reboot
'# InstallationBehavior.RebootBehavior = 2 Can request reboot
blnRebootRequired = True
End If
End If
Next
WScript.Echo strServer & " has " & intPendingInstalls & " updates pending installation"
If blnRebootRequired Then
WScript.Echo strServer & " WILL need to be rebooted to complete the installation of these updates."
Else
WScript.Echo strServer & " WILL NOT require a reboot to install these updates."
End If
'#
'#
'#
If blnRebootPending Then
WScript.Echo strServer & " is waiting for a REBOOT to complete a previous installation."
End If
End Function
'#
'#
'#
Function GetArgValue( intArgItem, strDefault )
If WScript.Arguments.Count > intArgItem Then
GetArgValue = WScript.Arguments.Item(intArgItem)
Else
GetArgValue = strDefault
End If
End Function
Basically I am looking for a code to put in somewhere there, where the server names input that shall be manually given after command execution in CLI can be given in a text file; like a lot of servers in text file and each server is executed one per line, one at a time by the script.
Cheers!
This allow to read from arguments collection and from standard input when - is passed as argument
Dim server
For Each server in WScript.Arguments.UnNamed
If server="-" Then
Do While Not WScript.StdIn.AtEndOfStream
WScript.Echo "Redirected: " + WScript.StdIn.ReadLine
Loop
Else
WScript.Echo "Argument: " + server
End If
Next
This allow to still pass arguments in the command line, and, if any of the arguments is a dash, the stantdard input is read. This will allow you to do any of the following
Usual argument pass
cscript checkServers.vbs server1 server2
Arguments and piped input
type servers.txt | cscript checkServers.vbs server1 server2 -
Only redirected input
cscript checkServers.vbs - < servers.txt
Redirected input and arguments
< servers.txt cscript checkServers.vbs - serverx
Or any other needed combination of arguments and standard input
type servers.txt | cscript checkservers.vbs server1 server2 - aditionalServer
EDITED to answer to comments
Option Explicit
Dim strServer
If WScript.Arguments.UnNamed.Length < 1 Then
CheckServerUpdateStatus "localhost"
Else
For Each strServer in WScript.Arguments.UnNamed
If strServer="-" Then
Do While Not WScript.StdIn.AtEndOfStream
strServer = Trim(WScript.StdIn.ReadLine)
If Len(strServer) > 0 Then CheckServerUpdateStatus strServer
Loop
Else
CheckServerUpdateStatus strServer
End If
Next
End If
WScript.Quit(0)
Obviously, you need to maintain your CheckServerUpdateStatus function, this code only handles the parameter input.
If you are trying to get the pending windows update installs for a bunch of computers, you can use this in Powershell:
$computers = gc text_file_of_computers.txt
ForEach ($computer in $computers) {
("-" * 30)+"`n" # Horizontal line
Write-Host "Patches not yet installed for $($computer)" -f "Yellow"
Get-Hotfix -co $computer| Where {$_.InstalledOn -eq $null}
"`n"+("-" * 30) # Horizontal line
}
As you can see, we only show patches which have a $null value for InstalledOn, which means they have not been installed as yet.
powershell

SFTP Transfer with Proxy?

Can the following WinSCP VBScript file be modified to allow proxy connection?
'###########################################################################
'# Function: MISC_FTPUpload
'#
'# Description:
'# Uses the FSO object to FTP a file to a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP to
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalFile - The Locally stored file to FTP to the remote server
'# (in) sRemotePath - The path to store the file in, on the remote server
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully sent
'# False - File not successfully sent
'###########################################################################
Function MISC_FTPUpload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalFile, byVal sRemotePath, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim bRetCode
Dim sFTPTempFile
Dim oFTPScript
Dim sResults
Dim sOut
Dim sCmd
LOG_Write "MISC_FTPUpload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalFile = Trim(sLocalFile)
'----------Path Checks---------
'Here we will check the path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
If InStr(sLocalFile, " ") > 0 Then
If Left(sLocalFile, 1) <> """" And Right(sLocalFile, 1) <> """" Then
sLocalFile = """" & sLocalFile & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason, Unexpected results may occur.
sRemotePath = "\"
End If
'Check the local path and file to ensure
'that either the a file that exists was
'passed or a wildcard was passed.
If InStr(sLocalFile, "*") Then
If InStr(sLocalFile, " ") Then
sError = "Error: Wildcard uploads do not work if the path contains a space." & vbNewLine & "This is a limitation of the Microsoft FTP client."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
'nothing to upload
sError = "Error: File Not Found."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "put " & sLocalFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPUpload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPUpload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
'###########################################################################
'# Function: MISC_FTPDownload
'#
'# Description:
'# Uses the FSO object to FTP a file from a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP from
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalPath - The path to store the file in, on the local drive
'# (in) sLocalPath - The path to get the file from, on the remote drive
'# (in) sRemoteFile - The remotely stored file to FTP to the local drive
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully retrieved
'# False - File not successfully retrieved
'###########################################################################
Function MISC_FTPDownload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalPath, byVal sRemotePath, byVal sRemoteFile, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim sFTPTempFile
Dim bRetCode
Dim oFTPScript
Dim sResults
Dim sCmd
Dim sOut
LOG_Write "MISC_FTPDownload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalPath = Trim(sLocalPath)
'----------Path Checks---------
'Here we will check the remote path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason. Unexpected results may occur.
sRemotePath = "\"
End If
'If the local path was blank. Pass the current
'working direcory.
If Len(sLocalPath) = 0 Then
sLocalPath = oFTPScriptShell.CurrentDirectory
End If
If Not oFTPScriptFSO.FolderExists(sLocalPath) Then
'destination not found
sError = "Error: Local Folder Not Found."
LOG_Write sError
MISC_FTPDownload = False
Exit Function
End If
sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
oFTPScriptShell.CurrentDirectory = sLocalPath
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "get " & sRemoteFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPDownload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPDownload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
The proxy would have to act as a Man in the Middle for this. SSH (the protocol SCP uses for data transfer) was designed to prevent this.
On the line, where you add the open command:
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
... add the -rawsettings switch followed by the options relevant for your kind of proxy:
For example:
sFTPScript = ... & " -rawsettings ProxyMethod=3 ProxyHost=proxy" & vbCrLf
For details refer to:
https://winscp.net/eng/docs/scriptcommand_open
https://winscp.net/eng/docs/rawsettings
To use the proxy, first use the WINSCP GUI to connect specifying the proxy details. This will add the details of proxy in the configuration file (which is in the same directory as winscp.com) and then it should work. You can then pass the path of this configuration file to your execute process task and call the WINSCP.com executable.

Ping script with loop and save in a txt

i try to make an Ping script with vbs. I need a Script, that ping (no ping limit, the program will run all the time) a computername in the network every 2 seconds and save the results in a txt file.
For Example:
06/08/2010 - 13:53:22 | The Computer "..." is online
06/08/2010 - 13:53:24 | The Computer "..." is offline
Now i try a little bit:
strComputer = "TestPC"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& strComputer & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then
..........
Next
And than i don't know how to make it. (I'm new with vbs :-))
I hope some one can help me.
Greeting,
matthias
Try this
Option Explicit
Dim strHost, strFile
strHost = "www.google.com" '"127.0.0.1"
strFile = "C:\Test.txt"
PingForever strHost, strFile
Sub PingForever(strHost, outputfile)
Dim Output, Shell, strCommand, ReturnCode
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputfile, 8, True)
Set Shell = CreateObject("wscript.shell")
strCommand = "ping -n 1 -w 300 " & strHost
While(True)
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
Output.WriteLine Date() & " - " & Time & " | The Computer " & strHost & " is online"
Else
Output.WriteLine Date() & " - " & Time & " | The Computer " & strHost & " is offline"
End If
Wscript.Sleep 2000
Wend
End Sub
You put your pings inside a loop of some kind and then use Wscript.Sleep 2000 to sleep for 2 seconds.
Then you use the File System Object (FSO) to write to a file. Information can be found here.
Edit: Something like this might work:
Const OpenFileForAppending = 8
Dim fso, ts
Set fso = CreateObject("Scripting. FileSystemObject")
While 1 > 0 ' loop forever
Set ts = fso.OpenTextFile("c:\temp\test.txt", OpenFileForAppending, True)
' do your pinging code
'if ok
ts.WriteLine("OK")
'else
ts.WriteLine("Not OK")
'endif
ts.Close()
Wscript.Sleep 2000
Wend

Resources