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
VB Script

Avatar of undefined
Last Comment
UBB

8/22/2022 - Mon
remmett70

This line looks wrong

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath & strUserName & StrPas

Try

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUserName, StrPas
UBB

ASKER
thanks for the swift reply,

the error I now get is a "type mismatch"

same source: WSHNetwork.MatNetworkDrive
remmett70

The source in your post, has a misspelling.  It should be MapNetworkDrive, not MatNetworkDrive.  Verify that the script does not contain that misspelling.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
UBB

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

Try.

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, False, strUserName, StrPas
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
remmett70

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

strRemotePath = "\\blah\" & strUserName
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
RobSampson

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
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?
RobSampson

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
UBB

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
UBB

ASKER
the quesiton has become irrelevant and no longer requires an answer.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.