Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Graceful error handling...

Reply
 
Old 10-21-2009   #1 (permalink)
Jake


 
 

Graceful error handling...

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"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


My System SpecsSystem Spec
Old 10-21-2009   #2 (permalink)
Tom Lavedas


 
 

Re: Graceful error handling...

On Oct 21, 4:13*am, Jake <jak...@newsgroup> wrote:
Quote:

> 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
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: error handling VB Script
WMI Error Handling PowerShell
error handling PowerShell
Crash Course in Error Handling? PowerShell
Error Handling PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46