DonKwizote
asked on
Creating a batch file with user input
Hello Everyone,
I am fairly new to batch scripting and I am learning it bit by bit.
I would like to create a batch file that maps drives for users when they are in the office.
The batch file will ask the user "Are you in the office?" and if they answer Yes, the script will map the drives and if they answer No, the script will exit.
This is my first try and I know it's wrong because it doesn't execute.
Please correct my mistakes.....
echo Are you working in the Head office?
If Y goto :Y
else
exit
:Y
net use j: \\joburg\admin
net use k: \\kathmandu\data
net use r: \\rome\project
net use v: \\valencia\group
exit
I am fairly new to batch scripting and I am learning it bit by bit.
I would like to create a batch file that maps drives for users when they are in the office.
The batch file will ask the user "Are you in the office?" and if they answer Yes, the script will map the drives and if they answer No, the script will exit.
This is my first try and I know it's wrong because it doesn't execute.
Please correct my mistakes.....
echo Are you working in the Head office?
If Y goto :Y
else
exit
:Y
net use j: \\joburg\admin
net use k: \\kathmandu\data
net use r: \\rome\project
net use v: \\valencia\group
exit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry Bill, typing same time there I guess.
Steve
Steve
ASKER
Thanks Bill for the rapid response and the solution. Thanks also Steve for helping me understand more about batch files. :-)
You can always split up points you know.... or sometimes we feel like we waste our time. BTW if the user types Yes or yes into mine it will do the same as Y or y and please look if your machines have choice on as users will not necessarily be expecting to hit Y then return etc.
You can also do some other simplish checks such as checking the network range of the network you are on or similar from DHCP if you have hopefully something other than a 192.168.0.x range that someone is probably also using at home:
http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet?OpenDocument
Steve
You can also do some other simplish checks such as checking the network range of the network you are on or similar from DHCP if you have hopefully something other than a 192.168.0.x range that someone is probably also using at home:
http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet?OpenDocument
Steve
@Echo off
choice /T 10 /D Y /M "Are you in the office [Y/N]"
if errorlevel 255 echo ERROR & goto office
if errorlevel 2 goto not
if errorlevel 1 goto office
echo Escaped from the question, asssume not
goto not
:office
echo In the office
exit /b
:not
echo Not in the office
exit /b
or without using choice
@Echo off
set /P office=Are you in the office [Y/N]?
if /I "%office:~0,1%"=="Y" goto office
if /I "%office:~0,1%"=="N" goto not
echo Not sure where they are, maybe assume not
goto not
:office
echo In the office
exit /b
:not
echo Not in the office
exit /b
That checks case insensitively (/I) the first character of the response made against Y or N. You have to press enter with Set /p
Steve