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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MapNetworkDrive just stopped working?

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

I have a script which runs a VPN connection , maps a drive and copies a file accross.

It's been running fine for over two years.

However, all of a sudden the script has stopped working when trying to map the network drive....
Code:
' Update Msg
MsgIE "Mapping network drive, please wait..."

' Map network drive
objNetwork.MapNetworkDrive "x:", "\\servername\foldershare", False, "UserID", "Password"

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

at this point no x: drive is mapped and the error routine is called due to Err.Number <> 0

However, if we drop down to a command prompt and run the 'net use' command the network drive maps without a problem.

Any ideas why this has started to happen and how we can fix it?

Thanks,

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
You have only provided a code snippet. Provide your entire script so we don't have to guess if you have set objNetwork to any value.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
sorry, didn't think you'd need the whole script, it had been working for two+ years... but here you go :)

Code:
'VBScript to Connect to myvpn and retrieve myfile'
'For use by authorised personel only'

Option Explicit

On Error Resume Next

' Define vars
Dim OWS, intReturn, objIE, strIETitle, objShell, k, objNetwork, intButton

' define objects
Set OWS = CreateObject("Wscript.Shell")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

intButton = OWS.Popup("Retrieve myfile from myvpn, are you sure?",,"Retrieve myfile from myvpn",36) 

If intButton <> 6 Then
    WScript.Quit
End if

' Display Msg
InitIE "Connecting to myvpn, please wait..."

' Run VPN link
OWS.Run "%comspec% /c rasdial myvpn", 0, true

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

' Update Msg
MsgIE "Mapping network drive, please wait..."

' Map network drive
objNetwork.MapNetworkDrive "x:", "\\myserver\myfolder", False, "UserID", "Password"

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

'Pause script 3 sec
WScript.Sleep 3000

' Update Msg
MsgIE "Transfering file, please wait..."

' Transfer File
OWS.Run "%comspec% /c copy x:\myfile.ext c:\myfolder\myfile.ext /Y", 0, true

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

' Update Msg
MsgIE "Disconnecting network drive, please wait..."

' Drop network drive
objNetwork.RemoveNetworkDrive "x:"

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

'Pause script 3 sec
WScript.Sleep 3000

' Update Msg
MsgIE "Closing connection to myvpn, please wait..."

' Disconnect VPN
OWS.Run "%comspec% /c rasdial myvpn /DISCONNECT", 0, true

If Err.Number <> 0 Then 
      Error_Msg
      WScript.Quit
End If

' Close display box
Wscript.Sleep 3000
MsgIE "IE_Quit"

' Clean Up
Set objIE = Nothing
Set objShell = Nothing
Set OWS = Nothing
Set objNetwork = Nothing

' Display completed msg
Wscript.Echo "Transfer Complete!"

' exit
WScript.Quit

' ################# SUB ROUTINES ##################
Sub MsgIE(strMsg)
' Subroutine to display message in IE box and detect when the
' box is closed by the program or the user.
  On Error Resume Next
  If strMsg = "IE_Quit" Then
    blnFlag = False
    objIE.Quit
  Else
    objIE.Document.Body.InnerText = strMsg
    If Err.Number <> 0 Then
      Err.Clear
      blnFlag = False
      Exit Sub
    End If
    objShell.AppActivate strIETitle
  End If
End Sub

Sub InitIE(strMsg)
' Subroutine to initialize the IE display box.
  Dim intWidth, intHeight, intWidthW, intHeightW
  Set objIE = CreateObject("InternetExplorer.Application")
  With objIE
    .ToolBar = False
    .StatusBar = False
    .Resizable = False
    .Navigate("about:blank")
    Do Until .readyState = 4
      Wscript.Sleep 100
    Loop
    With .document
      With .ParentWindow
        intWidth = .Screen.AvailWidth
        intHeight = .Screen.AvailHeight
        intWidthW = .Screen.AvailWidth * .40
        intHeightW = .Screen.AvailHeight * .05
        .resizeto intWidthW, intHeightW
        .moveto (intWidth - intWidthW)/2, (intHeight - intHeightW)/2
      End With
      .Write "<body> " & strMsg & " </body></html>"
      With .ParentWindow.document.body
        .style.backgroundcolor = "LightBlue"
        .scroll="no"
        .style.Font = "10pt 'Courier New'"
        .style.borderStyle = "outset"
        .style.borderWidth = "4px"
      End With
      .Title = "Retrieve HLP Accounts"
      objIE.Visible = True
      Wscript.Sleep 100
      objShell.AppActivate strIETitle
    End With
  End With
End Sub

Sub Error_Msg()
    MsgIE "There was an error, please close this window and try again!"
    ' Disconnect VPN
    OWS.Run "%comspec% /c rasdial myvpn /DISCONNECT", 0
    'Drop network drive
    objNetwork.RemoveNetworkDrive "x:"
    Set objIE = Nothing
    Set objShell = Nothing
    Set OWS = Nothing
    Set objNetwork = Nothing
    WScript.Quit
End Sub

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
OK, that helps. In this section:
Code:
' Run VPN link
OWS.Run "%comspec% /c rasdial myvpn", 0, true

If Err.Number <> 0 Then
      Error_Msg
      WScript.Quit
End If

' Update Msg
MsgIE "Mapping network drive, please wait..."

' Map network drive
objNetwork.MapNetworkDrive "x:", "\\myserver\myfolder", False, "UserID", "Password"

If Err.Number <> 0 Then
      Error_Msg
      WScript.Quit
End If

Do you get an error when connecting to the VPN? Is it executing the WScript.Quit? Does it reach the point of giving the message "Mapping network drive"? If so what is the error produced?

I would alter the code as such to get more useful information from the script. (use after attempt to map drive)

Code:
If Err.Number <> 0 Then
      ErrText = Err.Number & " " & Err.Description
      MsgIE ErrText
      WScript.Quit
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi Mark,

Thanks for the quick reply.

The VPN part works fine and the 'two terminals' show in the sys tray, and as connected.

You then get the message 'MsgIE "Mapping network drive, please wait..."' , and htne the error routine fires.

I'll add your code and get back to you, it's a user in Malta, so bear with me, getting hold of them is not always easy!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Sounds good. The error code and description should help isolate WHY it is not mapping.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I tried it myself, nothing happens , the program now just hangs no message is displayed?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Interesting, OK lets break it down to simpler components. Try the following modified script just by itself.

Code:
Set objNetwork = CreateObject("Wscript.Network")
On Error Resume Next
objNetwork.MapNetworkDrive "x:", "\\myserver\myfolder", False, "UserID", "Password"
If Err.Number <> 0 Then
   MsgBox Err.Number & vbCrLf & Err.Description
End If



I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
nope my bad, forgot to add ErrText to the variable dim command, error msg now working.

But I cannot run it from here as i'm logged on the domain and it gives that 'cannot share with two different logons' message, so will test at home and get back tommorrow!

Cheers,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
ok, ran a test from home loast night, it worked first time with no errors.

Sent the new code to the client and they get the following error
(-2147024843) The network path was not found[/code]

Any ideas why this is happening?

If we use the command prompt and manually run the 'net use' command it maps the drive fine?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Anything change in ISPs or routing paths? Sounds to me like there is a timing issue and the script is timing out on mapping the drive.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Nothing changed AFAIK.

I've checked the routing & remote access service is disabled.

I've had them run Winsockxpfix

I've got them to force NetBIOS over TCP/IP , I cannot find any other threads pointing to anything else as the probelm.

The other thing is if we run the net use command from the dos prompt, it maps in a millisecond, yet I have a 3 second pause in my script, so I can't see it being a timing out issue, plus what is timing out?

It's not even got to the copy command when it errors, so nothing is trying to access the network drive to throw a 'not found error' , it's dying on the 'MapNetworkDrive' command itself.

I'm at a loss, looks like we are going to have to throw the scripts away and just do it manually from now on, as VBScript or something is not working on that machine anymore and I can't work out what!

Infact i've found a thread on another forum asking the same questions in july 2006 and still no-one has repleid with an answer - so what does that tell you?





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Verify that the user doesn't already have an X drive mapped. If they do remove it or alter your script to use a different drive letter.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
they don't , already checked , plus the error routine removes network drive and closes the vpn connection

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
What happens when you open a command window and run this line by itself?

%comspec% /c rasdial myvpn

This is your line 26 from the program. On my workstation I receive a 623 error because I don't have a RAS/VPN connection. But your program reads this as a zero error. and passes through to the next command of connecting the network drive where it fails from no network connection.

Something has been changed somewhere, don't give up so quickly. Work with Mark a little, he knows what he's doing.

Regards,
David.
 
the VPN is connecting fine, and the script pauses until the VPN has finished connecting, not sure what makes it work that way but it does,

the mapping network drive message doesn't even print until the VPN has finished connecting.

and the error isn't instant nor is it 3 seconds later (ie the pause statement) it takes like 10+ seconds before it errors with 'network path not found?'

and that isn't the copy command throwing that as the "transferring file" message isn't shown.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Still waiting for results of my shorter code:

Code:
Set objNetwork = CreateObject("Wscript.Network")
On Error Resume Next
objNetwork.MapNetworkDrive "x:", "\\myserver\myfolder", False, "UserID", "Password"
If Err.Number <> 0 Then
   MsgBox Err.Number & vbCrLf & Err.Description
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I posted it .....
(-2147024843) The network path was not found

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Sorry I thought that was from you rerunning your code.

How long is the delay when you ping that server?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top