On Oct 21, 4:13 am, Jake <jak
...@gmail.com> wrote:
> Hi,
> In my logon scripts I do some drive mappings. Se code below.
> However if there is an error in connecting to one of these drives, the
> script throws an error and quits further executing.
> How can I in vbs do a (pseudo code)
> <if NOT nwo.MapNetworkDrive strDriveLetter, strPath" then
> ShowMessage("Error in mapping " & strDriveLetter & " to " & strPath)>
> ... and have the script continue execution on the next line?
> What are the offending linenumber and charnumber variables in vbs if I
> want to display these in the message box?
> Thanks for help on this
> regards
> jake
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sub DeleteMapping(strDriveLetter)
> 'Remove former login's drive letters
> 'Give the PC time to do the disconnect, wait 300 milliseconds
> If fso.driveexists(strDriveLetter) Then
> nwo.RemoveNetworkDrive strDriveLetter, True, True
> wscript.sleep 300
> End If
> End Sub
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sub MapMyDrives(strDriveLetter, strPath, strDescription)
> 'Remove former login's drive letters
> 'Map drive to new letter...
> 'Set friendly name
> DeleteMapping strDriveLetter
> nwo.MapNetworkDrive strDriveLetter, strPath
> sao.NameSpace(strDriveLetter).Self.Name = strDescription
> End Sub
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> MapMyDrives "R:", "\\172.23.1.10\Installations$", "Program Installers"
> MapMyDrives "S:", "\\172.23.1.10\Info$", "Information folders"
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VBS has only the 'On Error Resume Next' statement for such error
trapping. The Err object can then deliver the error number and its
description, if there is one, but there is no way to programmatically
return the line number or character. That information is just not
available to the script. Therefore the best that could be done is
something like ...
function MapMyDrives(strDriveLetter, strPath, strDescription)
'Remove former login's drive letters
'Map drive to new letter...
'Set friendly name
on error resume next
DeleteMapping strDriveLetter
if err.number <> 0 then
ShowMessage(Err.description & " on " & strDriveLetter & " to " &
strPath)
MapMyDrives = false
exit sub
end if
nwo.MapNetworkDrive strDriveLetter, strPath
if err.number <> 0 then
ShowMessage(Err.description & " on " & strDriveLetter & " to " &
strPath)
MapMyDrives = false
exit sub
end if
sao.NameSpace(strDriveLetter).Self.Name = strDescription
if err.number <> 0 then
ShowMessage(Err.description & " on " & strDriveLetter & " to " &
strPath)
MapMyDrives = false
exit sub
end if
MapMyDrives = true
End function
I also changed the routine to a function that returns True if
successful and False for a failure for testingf in your main routine.
_____________________
Tom Lavedas