Re: Err values from MapNetworkDrive failures

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: robert_shaw (robert_shaw_at_hotmail.com)
Date: 03/07/04


Date: 6 Mar 2004 20:33:29 -0800


> 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:

sub MakeVolPOutLog
on error resume next
Set VolpOut = fso.OpenTextFile(OutputFile, ForWriting, True,
TristateFalse)
WriteHeader = VolpOut.Write("VOLP (VolPrint) Printed on:
"&Today&vbcrlf)
VolpOut.close
i=0
For Each element In Servers
Err = 0
'Initializing Err at top of loop. Otherwise it'll retain the error
value.
DriveMapping = WshNetwork.MapNetworkDrive("X:", Servers(i))
'Servers() is an array of strings ("\\server\sys") built in a previous
Sub
'--->If the mapping fails, it'll fail here.
If Err = 0 then 'Knowing a failure will produce something other than 0
for Err allows me to test easily.
'I could probably test for the existence of "X:", but im a little lazy
;P
  WshShell.Exec("NDIR X:\ /VOL >>
c:\docume~1\robert~1\desktop\batch\VOLP-OUT.LOG")
'Pay attention to the running time of each drive mapping. This was
originally set to run as fast as the script would compute, but the
system didn't have time to complete the mapping. I dropped this
sleeper in to run for 3 seconds, then tested for shorter time-outs
later. Now it's 1/2 a second and seems to work OK. Hmmm... Increasing
to 3/4 second...
  WScript.Sleep 750
  Set VolpOut = fso.OpenTextFile("c:\docume~1\robert~1\desktop\batch\VOLP-OUT.LOG",
ForAppending, True, TristateFalse)
else
  Set VolpOut = fso.OpenTextFile("c:\docume~1\robert~1\desktop\batch\VOLP-OUT.LOG",
ForAppending, True, TristateFalse)
'BINGO! Thank you Michael Holzemer. "Err.Description" is my detail.
MappedDriveFailure(i) = "Failed to map to "&Servers(i)&". Error
#"&Err&vbcrlf&"Description: "&Err.Description
WshShell.Popup MappedDriveFailure(i),0,,0
VolpOut.Write MappedDriveFailure(i)
MappedDriveFailureHit(i) = 1
End If
'By making this a public var, I can use it later when I parse this
file and have to explain why the data's missing.
VolpOut.write "###########END "&Servers(i)&"###########"&vbcrlf
VolpOut.close
WshNetwork.RemoveNetworkDrive "X:"
i=i+1
next
end sub 'MakeVolPOutLog

So, where did you read/learn about the .description object? I thought
I'd read *most* of the MS white papers about VBScript - clearly I'm
missing a resource! (Although I have to admit, I've only read the
freebies online - I don't have the resources to pay for a book that'll
tell me what online dox *should* tell me.)



Relevant Pages