Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if network drive is maped?? 2

Status
Not open for further replies.

TheNewOne

Technical User
Joined
Mar 27, 2004
Messages
117
Location
SI
Heloo forum. I need help with my script.
I need to check if network drive in my script is really maped (sometimes drive wont map, because password has been changed). My scipt tell me only if maping was sucesefull, but wscript.echo isn't displayed if maping fails. THX for any help

Set Nw = CreateObject("WScript.Network")

Dim iReturn
iReturn = Nw.MapNetworkDrive("X:","\\server\share", , "user" , "password")
If iReturn <> 0 Then
'wscript.echo "Runtime error : " & cstr(iReturn) & vbcrlf & "Drive mapping failed."
wscript.echo "Drive mapping failed."
Else
wscript.echo "Drive mapping done."
End If

I found this script there on a forum, I think it's yours tsuji, but I cant set it to work corectly.
 
Hi thenewone,

I think the code you gave us is part of a script. not?
and somewhere above tou used 'On Error Resume Next' not?

normally if you give wrong credentials using the mapnetworkdrive method (and without using 'On Error Resume Next') you should get this error:
err.number = -2147023570
err.description = Logon failure: unknown user name or bad password.

I use this:
Code:
Set Nw = CreateObject("WScript.Network")

Dim iReturn
On Error Resume Next
Err.clear
Nw.MapNetworkDrive("Z:","Networkdrive", , "Userid" , "Password")  
If Err.Number = 0 Then
	wscript.echo "Drive mapping done."
Else If Err.Number = -2147023570 Then
	wscript.echo "Drive mapping failed."
Else
   wscript.echo "ERROR: " & Err.Number & " - " Err.Description
End If
On error goto 0

Hope this helps...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
THX K0b3 for great solution. THX for your time again. Rock on.

Jure, Slovenija
 
TheNewOne,

Glad you've got excellent advice. I'm not sure your listing is mine, I can't recall and it doesn't look likely. If you've a link could you post it just for me to review?

regards - tsuji
 
TheNewOne,

Okay, I see how it was built upon. Thanks.

- tsuji
 
TheNewOne,

Just a side-note, if you read more carefully the referred thread, the iret is not built on the Nw.MapNetworkDrive() but a custom function with return the error number. The way you remodelling it is surely wrong---that's why I want a review of what I did, if it is mine. I see you make an effort and you'll get to it in no time. Thanks for the time.

- tsuji
 
Sorry for my lack of understanding this post tsuji. Im just a beginer in VB script and some things that are logicaly to you arent for me.
I wish you nice day.

Jure, Slovenija
 
TheNewOne,

No problem at all. I bring it up just want you to see the intriguing twist which might very much well not that obvious to everybody.

- tsuji
 
Not sure if you need any more help on this or not, but this is a similar scenerio. We need our script to wait until the logon script has completed, for a particular program to fire off, so we've added this script to the all users/startup. Hope this might be useful as well to everyone.

Code:
On Error Resume Next
Dim WshNetwork, FSO, WshShell
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

drv = "P"
DriveMappingComplete = 0

do while DriveMappingComplete <> 1
    ReportDriveStatus(drv)
loop


Function ReportDriveStatus(drv)
  Dim fso, msg
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.DriveExists(drv) Then
      DriveMappingComplete = 1
    Else
  End If
End Function

-SWarrior
 
THX SWarrior. Some very interesting steps in your script. I think I could incliude them into mine script. THX for your reply again. Star for you man :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top