script that asks user for credentials and maps drive

UBB
UBB used Ask the Experts™
on
hello,

I need to build a script that will prompt a login credentials that are different to their windows credentials.  
if the login is correct, it maps the I drive to a Unix Server

there is a net use command file used at the moment that maps the drive to a generic user account but I need it to map to specific user accounts?

so far, using different scripts online, I have managed to come up with the following.

Option Explicit
Dim objNetwork, objShell
Dim strDriveLetter, strRemotePath, strUserName, strPas
strDriveLetter = "I:"
strRemotePath = "\\Blah\%HOME%\"

' Purpose of the script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method. Result I: drive
Set objNetwork = WScript.CreateObject("WScript.Network")
' Here is where we extract the UserName
strUserName = InputBox("CIMS username ")
strPas = InputBox("CIMS password ")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & strUserName & StrPas

' Bonus code to open Explorer at the mapped drive letter
Call ShowExplorer
WScript.Quit

Sub ShowExplorer()
Set objShell = CreateObject("WScript.Shell")

I do not really have any VBS knowledge - its more trial an error on my part for the moment

when I run the above script, I am asked for username and password which is good but I then get an error.

Script: test.vbs
Line: 18
char: 1
Error: the specified network password is not correct

Code: 80070056
Source: WSHNetwork.MapNetworkDrive

any help would be great

Thanks
Naz
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
remmett70Network Manager

Commented:
This line looks wrong

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & strUserName & StrPas

Try

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUserName, StrPas
UBB

Author

Commented:
thanks for the swift reply,

the error I now get is a "type mismatch"

same source: WSHNetwork.MatNetworkDrive
remmett70Network Manager

Commented:
The source in your post, has a misspelling.  It should be MapNetworkDrive, not MatNetworkDrive.  Verify that the script does not contain that misspelling.
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

UBB

Author

Commented:
that was a typo on my part, not the script
the script is right, I was simply typing out the error
remmett70Network Manager

Commented:
Try.

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, False, strUserName, StrPas
UBB

Author

Commented:
now the error is "the network path was not found"

I have been doing some testing using net use and I found the following (which will cause more problems now)

when I use

net use i: \\Blah\%HOME% "password" /user:username

from my machine

it doesnt map the I drive, but whehn I use

net use i: \\Blah\username "password" /user:username

it maps the drive??????

so now the problem is how do I get this script to work like this?  I did try and add the change variable from
strRemotePath = "\\Blah\%HOME%\"
to
strRemotePath = "\\Blah\strUserName"

but that didnt work

hope you can help

ps: the path is to a samba share by the way

Regards
remmett70Network Manager

Commented:
Try.   Make sure you move this to after you prompt for username to be entered.

strRemotePath = "\\blah\" & strUserName
UBB

Author

Commented:
this is what I have so far

Option Explicit
Dim objNetwork, objShell
Dim strDriveLetter, strRemotePath, strUserName, strPas
strDriveLetter = "I:"

' Purpose of the script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method. Result I: drive
Set objNetwork = WScript.CreateObject("WScript.Network")
' Here is where we extract the UserName
strUserName = InputBox("CIMS username ")
strPas = InputBox("CIMS password ")
strRemotePath = "\\Blah\" & strUserName
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, False, strUserName, StrPas

' Bonus code to open Explorer at the mapped drive letter
Call ShowExplorer
WScript.Quit

Sub ShowExplorer()
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" & " " & strDriveLetter & "\" )
End Sub

When I run the script, it asks me the username and the password (I need to hide the password), and then I get the attached error message.

thanks
script-error.png
Most Valuable Expert 2012
Top Expert 2014

Commented:
This error means that you already have a connection to a share somewhere on \\tbfp01, connected as UserA.  You cannot therefore, connect a drive to a share on \\tbfp01 using UserB credentials.  You must disconnect all connections from UserA before you can map the drive as UserB.

Regards,

Rob.
UBB

Author

Commented:
Hi,

this network drive is not shared on TBFP01, TBFP01 refers to another windows share that maps user home drives and shared resource.
the drive I am trying to map is a samba share stores on the unix server.
How come it works when I enter the indivudual user drive nane?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Oh yeah, I see.  TBFP01 is just where the script is.  So you're mapping to
strRemotePath = "\\Blah\" & strUserName

Try logging off, then logging on, and running the script again.  If you get the same error, run a command prompt and type
net use

and see if there are any other connections to \\blah

Rob.
Commented:
hello. This quesiton can be closed now as it has become irrelevant due to changes within the business.
thanks, regards
UBB

Author

Commented:
the quesiton has become irrelevant and no longer requires an answer.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial