![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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" > > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 Specs![]() |
![]() |
| 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 | |||