0

I am trying to create a batch file that will allow a user to input a login and password when it come to mapping a network drive. This is what I have so far:

net use X: \\domain.local\SharedApps /user:domain.local\LOGIN "PASS" 
- I have to run this command manually in admin CMD as i dont know how to elevate it in the script. It maps the drive in CMD admin so the rest of the batch files can run.
call X:\_NewComputers\SyncDist.bat 
- Syncs files that allow the running of JoinDomain
timeout 360 
- SyncDist downloading files so i placed this to prevent the bat's from overlapping
call X:\_NewComputers\JoinDomain.bat
- Joins the domain and restarts the computer to run scripts for printers and Network Drives

I have removed the user and pass from the batch. I want the user to input that information so that if a random user opens the file they don't have administration credentials.

Is it even possible to do it in a batch file or would it have to be a different language and call on the batch file itself?

I can also provide the Other batch file makeups if required they are mostly linking to their respective files elsewhere in the drive. Any help is welcome.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
will309
  • 13
  • 1
  • 5

1 Answers1

0

To elevate a batch script, check out this script, it is easy to use, just copy to the end of your file and create a batch file like the example.

To input username and password to a variable, use this:

set /p _username=Type your username:
set /p _password=Type your password:

and to use the saved variables later:

net use X: \\domain.local\SharedApps /user:domain.local\%_username% %_password% 

JFYI: you do not neet to map a network drive to use it, if your credentials already have permission for it. You can simply use 'pushd':

pushd \\domain.local\SharedApps

This will create a temporary mapped drive using an available drive letter, then you can do all your work and remove the temporary drive with 'popd' command.

If you use the admin elevation script mentioned above, you might be able to map the drive with pushd, having no need to ask for username and password again.

Community
  • 1
  • 1
cyberponk
  • 1,585
  • 18
  • 19
  • Using PUSHD without a drive letter will work. But, remember the caveat that it uses an available drive letter. Once the ~26 or so drive letters are exhausted, things will start failing. It is not too hard to exceed the limit in a situation where multiple .bat scripts are run and/or calling each other. – lit Apr 26 '17 at 21:43