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!

Maping to a remot drive as different user

Status
Not open for further replies.

JojoNo1

Programmer
Jul 14, 2005
7
CA
Hi
I’m trying to write a small utility that allows people to map to a remote drive without making the connection persistent.
So I use the code below in a window form
Dim WshNetwork As Object
WshNetwork = CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive("E:", "\\SomeServer\SomeShare", , txtUsername.Text.ToString, txtPassword.Text.ToString)

the problem is the MapNetWorkDrive does not care what password I supply , I could type "mypassword" or "hello" and it will still work as long my txtUsername =domain\ntAccount.

then this is the kicker if I want to log in to a certain share as a different user/ password (given userid & password are valid)I get the dreadful error "Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.."

Any thought any suggestions, any other ways in .net/ windows form asp.net...
Regards

 
Have to first removenetworkdrive before re-map with different credential?
[tt] WshNetwork.RemoveNetworkDrive "E:",true,false[/tt]
Further, try not to enclose the argument of mapnetworkdrive with parentheses. That is not the correct way to do it.
[tt] WshNetwork.MapNetworkDrive[highlight] [/highlight]"E:", "\\SomeServer\SomeShare", [green]false[/green], txtUsername.Text.ToString, txtPassword.Text.ToString[highlight] [/highlight][/tt]

 
I did
WshNetwork.RemoveNetworkDrive("E", True, True)
and then I do
WshNetwork.MapNetworkDrive "E:", "\\SomeServer\SomeShare", false, txtUsername.Text.ToString, txtPassword.Text.ToString

I still get the error
"Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.."

P.S.
this happenes only when I use different user/password than the logged on user top the machine, and I do not know of a way to start WshNetwork with different credential, because before I execute the MapNetwork method if I check
?WshNetwork.UserName
I get the logged on user.
to replicate the error just cut and past in vbs file and connect using a different user credential after you removed the share and you will get the same error.
Any thoughts.
Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top