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

Re: Script to distribute shortcut with error handling by James

James
Thu Jan 24 12:25:32 CST 2008

"Newyorker909" <olly120@gmail.com> wrote in message
news:06ff305b-6694-4cee-81d9-048304ffa3eb@k39g2000hsf.googlegroups.com...
> 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

I would suggest using 'On Error Resume Next' for your shortcut creation
code and then testing for the existance of the shortcut after creation:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If Not oFSO.FileExists(DesktopPath & "\myshortcut.lnk") Then
oTSOut.WriteLine "Error on " & sComputer & _
":" & Err.Number & ", " & Err.Description
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I also noticed that your shortcut code is designed around writing a
shortcut to the desktop for your personal profile on the local desktop for
which the script is run on. Is this your intention?