Link to home
Start Free TrialLog in
Avatar of UBB
UBB

asked on

script that asks user for credentials and maps drive

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
Avatar of remmett70
remmett70
Flag of United States of America image

This line looks wrong

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & strUserName & StrPas

Try

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUserName, StrPas
Avatar of UBB
UBB

ASKER

thanks for the swift reply,

the error I now get is a "type mismatch"

same source: WSHNetwork.MatNetworkDrive
The source in your post, has a misspelling.  It should be MapNetworkDrive, not MatNetworkDrive.  Verify that the script does not contain that misspelling.
Avatar of UBB

ASKER

that was a typo on my part, not the script
the script is right, I was simply typing out the error
Try.

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

ASKER

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
Try.   Make sure you move this to after you prompt for username to be entered.

strRemotePath = "\\blah\" & strUserName
Avatar of UBB

ASKER

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
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.
Avatar of UBB

ASKER

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?
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.
ASKER CERTIFIED SOLUTION
Avatar of UBB
UBB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UBB

ASKER

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