Hello All.
Please can someone point me in the right direction
I am hoping to use a script that will connect to each pc listed in a
txt file and write to another txt file the pc's that were unreachable,
before copying a shortcut on the users desktop to the PC's that are
reachable.
This is crucial as I need to log the pc's that were not reached so
that I can push to them later.
I have placed the shortcut copying part in a subroutine and it has
tested fine.
Can someone advise me on the best way to test the connection for error
handling? In particular what would be best practice to connect to the
PC's in the ***MAKE CONNECTION*** section??? (WMI or ping???)
Any sample code would be appreciated.
******************************************************************
'Create a FileSystemObject
Set oFS = _
CreateObject("Scripting.FileSystemObject")
'Open a text file of computer names
'with one computer name per line
Set oTS = oFS.OpenTextFile("c:\computers.txt")
Set oTSOut = oFS.CreateTextFile("c:\errors.txt")
'go through the text file
Do Until oTS.AtEndOfStream
'get next computer
sComputer = oTS.ReadLine
On Error Resume Next
'***MAKE CONNECTION*** '
If Err <> 0 Then
oTSOut.WriteLine "Error on " & sComputer & _
":" & Err.Number & ", " & Err.Description
Else
On Error Goto 0
'***REST OF CODE HERE
'********************************************************************************************
Add_Shortcut
Sub Add_Shortcut
On Error Resume Next
Dim oFS, oWsh, oNetwork, strUser, Shell
Dim DesktopPath, link
Dim folder, file,
Set oWsh = CreateObject("WScript.Shell")
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set oNetwork= CreateObject("Wscript.Network")
Set Shell = CreateObject("WScript.Shell")
strUser = oNetwork.UserName
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\myshortcut.lnk") 'the
new shortcut name
link.TargetPath = "\\server1\share$\file.exe"
link.Save
End sub
'***********************************************************************************************
End If
Loop
oTS.Close
oTSOut.Close