Need help with creating a subst .bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dawidx0
Posts: 2
Joined: 14 Jan 2014 03:40

Need help with creating a subst .bat

#1 Post by dawidx0 » 14 Jan 2014 03:58

Hello forum, I am a complete "noob" at notepad coding, and I need your help.

So the basic idea is to create a .bat file and whenever you open it, it tells you to enter "your login", and after you enter the login, it transfers the login to an actual script line to open a folder. (How bad of an explanation)! For example.

Hello, please enter your login.
*user enters 07user*
The script will proceed to open a location for example:

c:/folder/07user.

and here's my current "code" I'm using.

Code: Select all

@echo off
color ac
title Subst Local Drive
echo Working...
subst X: C:/
echo Opening X:\Users\user1...
explorer X:\Users\user1
echo Done!
echo Shutting down...
timeout 3



penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Need help with creating a subst .bat

#2 Post by penpen » 14 Jan 2014 09:18

Something like this?

Code: Select all

@echo off
setlocal
color ac
title Subst Local Drive
set /P login=Hello, please enter your login.^


:: the 2 empty lines above are needed don't remove
echo Working...
subst X: C:/
echo Opening X:\Users\%login%...
explorer X:\Users\%login%
echo Done!
echo Shutting down...
timeout 3
endlocal
If the login is the same as in the batch variable %USERNAME% you could avoid the set /P.
(Warning not check for validity integrated.)

penpen

dawidx0
Posts: 2
Joined: 14 Jan 2014 03:40

Re: Need help with creating a subst .bat

#3 Post by dawidx0 » 15 Jan 2014 04:12

Thanks so much, penpen.

The login looks something like this: 07smithj

Works perfectly.

Post Reply