Script help required please

Thanks dude.

Easy one for you, can you please write me a script to look at the same text file, and ping the pc name. If it is not pinging, can we output the results to a text file?

Thanks again!
 
Dont worry seem to have fixed it, although not sure how lol

If you have time to do the above script that would be great :D

edit: used part of your code and an example i found... just need to work it out how to output it to a file and append, not a messagebox

Code:
'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("list.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")

'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then
wscript.echo strHost & " is pingable"
Else
wscript.echo strHost & " is not pingable"
End If

Loop
File.Close
WScript.Echo "Complete"
WScript.Quit
 
Last edited:
This kinda does what I need. Would be better not to have all the stuff from the ping result, ie ping statistics, and the code at the top (The this session was run stuff) doesnt work, but lol

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")



Shell.Run "Cmd.exe /c Ping.exe -n 2 " & strHost  &" >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo. >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo ********************************** >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True


Loop
File.Close

Shell.Run "Notepad.exe C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit


erm, well I noticed that the bottom >> append was pointing to the wrong file, hence why I couldnt see the head text... but now I cant see the results!

Six6siX I need you!
 
Last edited:
Yay fixed it

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")



Shell.Run "Cmd.exe /c Ping.exe -n 2 " & strHost  &" >> Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo. >> Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo ********************************** >> Pingfile.txt", 2,True


Loop
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit
 
Oops, sorry I wasn't at my PC much!

Nice one though :D

I was just reading through your code and thought I should refresh the page just in case you'd done it!

So it reads the original list, pings, if it gets a reply, adds machine to new list. Then from the new list, performs the copy/unregistering/registering?
 
I think I've done it mate, hold tight

edit:

This seems to do the job

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")


'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then

Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)

Else

Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is not pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
End If
TheFile.Close

Loop
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit


Another edit:

So Im not opening and closing the file each loop.

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)


'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")


'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then


TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)

Else


TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is not pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
End If


Loop
TheFile.Close
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit
 
Last edited:
Nice one, looks ok to me! :)

If you don't need visibility on which hosts are actually up, you could link the two scripts together so the other part runs using the live hosts (pingfile) immediately after you've generated it.
 
Not quite sure how mate.... erm

Shell.Run ("taskkill /s" & strLine & " /im scale.exe")

Something like that?

well

Set Shell1 = CreateObject("Wscript.Shell")
Shell1.Run ("taskkill /s" & strLine & " /im notepad.exe")

Didnt work :(
 
Last edited:
Code:
Set Shell = CreateObject("Wscript.Shell")
	Return = Shell.Run ("taskkill /s " & strLine & " /im scale.exe", 1, true)

Would look for and kill image name scale.exe on remote computer name strLine

You don't need the Set Shell = ... bit if you already defined it in the code, I just included it here for completeness!


edit...
I think in your code above you missed a space between the /s and the computer name?
 
quick question if you are still around..... the copy, does it wait for the file to be copied, before running the register? Its going across the wan so may take a little while.

Thanks
 
A[L]C;19318232 said:
quick question if you are still around..... the copy, does it wait for the file to be copied, before running the register? Its going across the wan so may take a little while.

Thanks

I believe it does..so there shouldn't be any problems (I haven't come across any!) Using the CopyFile method, the script should wait till the process is complete before continuing.

If you want an alternative with say a progress bar to indicate completion and then move onto the next item then you'd need to change to the CopyHere method and call the explorer file transfer dialog (vbs doesn't have a native progress bar)
 
Back
Top Bottom