Re: Err values from MapNetworkDrive failures

From: Michael Holzemer (mholzemer.greyhair_at_pacbell.net)
Date: 03/08/04


Date: Sun, 7 Mar 2004 18:33:50 -0800

In item <f79665bf.0403062033.40aef5a9@posting.google.com>,
robert_shaw says...

>> First of all have you looked at the err.description of these events? If you
>> post your code and show where the error occurs that would make it easier to
>> answer your question.
> Okay! No, I hadn't looked at err.description. I didn't know it
> existed.
> Adding this to a global var gives me a much better answer:
> "An extended error has occurred."
> Sounds a lot better than:
> "-2147023688"
> As for the code, it looks like this:

< snip >

I changed the code slightly. I was not able to reproduce your error because I do
not have the ndis program. I suspect that is where your error is coming from. In
addition to Michael's post on documentation the entire Scripting Guide is
available online.

Here is the code adjusted.
Const forappending = 8
Const Forwriting = 2
Set fso = CreateObject("scripting.filesystemobject")
Set WshNetwork = CreateObject("wscript.network")
Set WshShell = CreateObject("wscript.shell")
Servers = Array("\\129.0.1.1\f$", "\\127.0.0.1\c$")
MakeVolPOutLog
Sub MakeVolPOutLog
 On Error Resume Next
 Set VolpOut = fso.OpenTextFile _
 ("c:\myfile.log", ForWriting, True, TristateFalse)
 WriteHeader = VolpOut.Write _
 ("VOLP (VolPrint) Printed on: " & Today & vbCrlf)
 VolpOut.close
 '// I changed this because you were not using element
 '// you were using the array subscript
 For i = 0 To Ubound(Servers)
  '// check for X
  If Not FSO.DriveExists("x:") Then
   DriveMapping = _
   WshNetwork.MapNetworkDrive("X:", Servers(i))
   '// This sleep needs to be here not after
   '// you execute a program on the drive
   WScript.Sleep 750
  End If
  msgbox Err.description
  If Err.Number = 0 Then
   '// I switched to run so I can ensure this command
   '// completes before moving on
   '// I also made sure it runs from the command line
   WshShell.Run _
   "%comspec% /c NDIR X:\ /VOL >> c:\VOLP-OUT.LOG",,True
   Set VolpOut = fso.OpenTextFile _
   ("c:\VOLP-OUT.LOG", _
   ForAppending, True, TristateFalse)
   '// Check to see if there is an error running ndir
   msgbox Err.description
  Else
   msgbox "hit this Loop"
   '// this turns error handling off
   '// so any error after this will pop
   On Error goto 0

   Set VolpOut = fso.OpenTextFile _
   ("c:\VOLP-OUT.LOG", ForAppending, True, TristateFalse)
   '// the (i) after Mapped drive failure
   '// throws an error because it is expecting
   '// an array. Are you passing on in?
   MappedDriveFailure = "Failed to map to " _
   & Servers(i) & _
   ". Error#" & Err.Number & vbCrlf _
   & "Description: " & Err.Description
   WshShell.Popup MappedDriveFailure,0,,0
   VolpOut.Write MappedDriveFailure
   MappedDriveFailureHit = i + 1
   err.clear
  End If
  VolpOut.write "###########END " & Servers(i) _
  & "###########" & vbCrlf
  VolpOut.close
  '// Make sure the drive it there before
  '// trying to remove
  If FSO.DriveExists("x:") Then
   WshNetwork.RemoveNetworkDrive "X:"
  End If
 next
End Sub 'MakeVolPOutLog

So to troubleshoot the first thing I did was comment the on error resume next,
that allows me to see where the script stops. I added it back in later and put
in an on error goto 0 to turn it off in a certain spot. See if this helps you.

-- 
Regards,
Michael Holzemer
No email replies please - reply in newsgroup
Learn script faster by searching here
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp


Relevant Pages