Jump to content

Mapping network drive on domain from shared resource


Recommended Posts

Hello guys and gals I have been trying to implement a script/exe here and I am running into brick walls.

Basically what I want is a prompt for username and password and then based on the input to map a drive. i.e. username is JohnDoe and password is JD01234. After entering that information it would map a drive letter X to \\fileshare\users\johndoe (the only variable is the actual username \\fileserver\users stays the same every time.)

I used as reference but cant seem to get it working

This is being done from a domain user account that is logged in and a shared computer. We do not want a million people logging into the machine under their domain creds because it just fills with junk user accounts and annoys us. So one account to rule them all. Now the issue is mapping the drive.

Can anyone help me out please and thank you?

Link to comment
Share on other sites

  • Moderators

Hi, thebearjuden, welcome to the forum. This works just fine for me.

$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("X:", "fileshareusersjohndoe", 0, $username, $pw)

Are you receiving an error when running your script?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks much for the reply.

I tried what you have here and I get no error with running that as the script BUT it does not map the drive at all.

I want fileshareusers to remain constant but the johndoe to change based on what they are putting in for creds. so johndoe, janedoe, johnnyuser, janeuser at the prompt would equal a map of X being direct at fileshareusers(whatever they put for their username) if that makes sense?

when I tried using the script in that other thread I would just end up with "Undefined / Other error. Windows API return code" which I believe is built in but I have no idea the cause of it.

Link to comment
Share on other sites

I believe you need to use "DomainName" & $username instead of just the user name if you're using this on a domain.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I am a bit of a noob at this but trying to catch on and learn as fast as possible. I know this might seem stupid but ... like this?

$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("X:", "file01users", 0, "OURDOMAINHERE" & $username, $pw)
Link to comment
Share on other sites

  • Moderators

That would map the drive to just the users directory. If you want it to go to that particular user's directory, you would need to map it something like this:

"file01users" & $username

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

DriveMapAdd("X:", "file01users" & $username, 0, "OURDOMAINHERE" & $username, $pw)

This will will map the X: drive to the server location file01users<USERNAME> using the domain credentials. As long as the <USERNAME> folder exists in the users folder it should map it.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I just got this to work:

$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("X:", "file01users" & $username, $pw)

Now, is there something I can throw in here to make the drive X disconnect when the program is fired up again for someone new to connect?

Link to comment
Share on other sites

  • Moderators

Take a look at DriveMapDel in the helpfile. You could call that first, delete the drive mapping if it exists, and then create it anew.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guys! Amazing! It works!!!

; Disconnect
DriveMapDel("Q:")
$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("Q:", "file01users" & $username, $pw)

At least on my machine it does. I am going to go test it in the shared room with that machine now. I am VERY excited!

Iunfortunately had to change X to Q but whatever lol

Edited by thebearjuden
Link to comment
Share on other sites

  • 5 weeks later...

Ok .... now I am really confused.

It worked from my AD account but not any other. So i went digging and realized that even with my standard non DA account, I am a member of a few groups that this other account is not. No big deal ... or so I thought ...

So I dug into those and added the same groups etc and it still doesnt work UNLESS ...

Unless I add the user into an "IT" group which makes no sense because digging down on those doesn't show anything special.

Is there anyone that can just point a very frustrated sysadmin in a direction here?

This might be less of a script problem and more of an enviornment problem but I have no idea where to look right now.

Edited by thebearjuden
Link to comment
Share on other sites

You're not using the user name parameter in DriveMapAdd, you have the $pw variable in the Username location, with a blank password.

;This
DriveMapAdd("Q:", "file01users" & $username, $pw)
;should be this
DriveMapAdd("Q:", "file01users" & $username, $username, $pw) ;the first use of $username is mapping the folder location, the second is used for the credentials

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You're not using the user name parameter in DriveMapAdd, you have the $pw variable in the Username location, with a blank password.

;This
DriveMapAdd("Q:", "file01users" & $username, $pw)
;should be this
DriveMapAdd("Q:", "file01users" & $username, $username, $pw) ;the first use of $username is mapping the folder location, the second is used for the credentials

Didn't work that way either ;)
Link to comment
Share on other sites

Whoops, missed a parameter myself.

;This
DriveMapAdd("Q:", "file01users" & $username, $pw)
;should be this
DriveMapAdd("Q:", "file01users" & $username, 9, $username, $pw) 
;the first use of $username is mapping the folder location, the second is used for the credentials, also was missing the flags parameter which I also forgot
;the 9 represents persistent mapping and to show the authentication dialog if needed, you could also put in there 0 so that it isn't persistent and no dialog etc.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

OP: Are you able to post the code you have thus far? Might help people trying to help you without having to play the guessing game of what you have so far.

My thoughts are the following, nonetheless:

1) Check to see if putting the username and pw variables inside quotes works.

2) Make sure you are putting the domain followed by "" in front of the user name (as BrewManNH suggested).

3) If you have a static IP for the server, you can try that instead of its name in the path.

Link to comment
Share on other sites

This is what I have so far:

; Disconnect
DriveMapDel("Q:")
$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("Q:", "file01users" & $username)

I have also tried:

; Disconnect
DriveMapDel("Q:")
$username = InputBox("Drive Mapper", "Please enter User Name")
$pw = InputBox("Drive Mapper", "Please enter Password", "", "*")
DriveMapAdd("Q:", "file01users" & $username, 9, $username, $pw)

I keep getting errors on line 5 when compiling if I add the domain.com$username or even domain$username

Link to comment
Share on other sites

You'd need to put that in there as "domain" & $username because you need to separate the string "domain" from the variable $username. Also, are you actually compiling this when you try it, or are you running it first? Because with AutoIt, you don't have to compile a script before you can test it, most of the time.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...