Batch File Issue In Creating Folders In Win7

May 23, 2011 at 02:52:13
Specs: Windows 7, Intel core 2 duo
Hi, I am having an issue in creating a folder for user2. My code is given below:

@echo off
cls
net user user1 /add
net user user2 /add
set /p UserName = Enter your username...
shift
if %UserName% == "user1" goto mkt
if %UserName% == "user2" goto fin
:mkt
md C:\Users\user1\Marketing
pause
net share Marketing_folder = C:\Users\user1\Marketing /remark:"Marketing for User1"
pause
net use /user:user1
pause
@echo on
exit
:fin
md C:\Users\user2\Finance
pause
net share Finance_folder = C:\Users\user2\Finance /remark:"Finance for User2"
pause
net use /user:user2
pause
@echo on
exit

I can create users and creater marketing for user1 but I cant create finance for user2. Please Help!!!
Cheers!!!


See More: Batch File Issue In Creating Folders In Win7

Report •


#1
May 28, 2011 at 01:20:31
what is the error on screen (command line)

Subhash Chandra.
http://www.wintechgeek.com


Report •

#2
May 29, 2011 at 19:31:35
This is the current version of my batch file:


@echo off
cls
net user user1 /add
net user user2 /add
set /p UserName =Enter your username...
if /I "%UserName%" == "user1" goto mkt
if /I "%UserName%" == "user2" goto fin
:mkt
md C:\Users\user1\Marketing
pause
net share Mark=C:/Users/user1/Marketing
pause
net use S: \\WINDOWS-PH03TJ1\Mark
pause
goto ex
:fin
md C:\Users\user2\Finance
pause
net share Finan=C:/Users/user2/Finance
pause
net use T: \\WINDOWS-PH03TJ1\Finan
pause
goto ex
@echo on
:ex
exit

The message it displays is Marketing Folder already exists. Or if i enter user2 for the first time, it says Marketing created and shared successfully! However, it doesnt create Finance folder!

Please help!!

Cheers!


Report •

#3
May 31, 2011 at 08:30:15
The message it displays is Marketing Folder already exists.
Does it? If so, I'm not seeing an issue.

Or if i enter user2 for the first time, it says Marketing created and shared successfully! However, it doesnt create Finance folder!
Of course not, it said Marketing was created successfully, not Finance. It's like ordering a pizza, and complaining you didn't get a hamburger!

On a more serious note, %UserName% is already defined by the system. That choice in variable names hid a bug, but reveled another.

- You're not assigning %UserName%, you're assigning %UserName % (note the space).

- You don't have a generic catch-all. As it is, you could enter user3, and it'll treat it as user1.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
May 31, 2011 at 12:54:43
@rev.. Note what Razor Said..
- You're not assigning %UserName%, you're assigning %UserName % (note the space).

See this line now.
set /p UserName =Enter your username...

See the space between "UserName and = " Remove this space and it will work fine..
Your current script treats the current loged in user as Username and try to match
if /i "loginusername" == User1 goto MKT
if /i "loginusername" == User2 goto FIN

Both of above are evulated as false so the command interpreter goes to next steps which is to execute the script in lable :mkt


Also, Razor mentioned that if someone enters user3 , it will also do the same thing. i slightly modified it ..try it..


:: =========================================================

:_start
@echo on
cls
net user user1 /add
net user user2 /add
set /p UserName=Enter your username...:
if /I "%UserName%" == "user1" (
md C:\Users\user1\Marketing
pause
net share Mark=C:/Users/user1/Marketing
pause
net use S: \\localhost\Mark
exit
)

if /I "%UserName%" == "user2" (
md C:\Users\user2\Finance
pause
net share Finan=C:/Users/user2/Finance
pause
net use T: \\localhost \Finan
pause
exit
)

Echo. You have entered an invalid value .
goto :_Start
:: ====================================================

What i dont understand is , Why you want to share a local folder and then map it as a new drive ?
You can use subst Drivename: Path to map a folder as drive..

Subhash Chandra.
http://www.wintechgeek.com


Report •

#5
June 1, 2011 at 05:21:50
THANKS SUBASH AND RAZOR. U GUYS ARE GENIUSES!!! I CAN'T BELIEVE IT! A SINGLE SPACE MADE A HUGE DIFFERENCE TO MY CODE! IT WORKS PERFECTLY FINE NOW! I AM VERY THANKFUL TO U GUYS FOR SPOTTING SUCH A MINUTE MISTAKE!

CHEERS AND GOD BLESS,

TREV


Report •

#6
June 1, 2011 at 10:55:55
:) Happy to help and thank you for taking time to post the feedback.

Credit to Computing.net...

Subhash Chandra.
http://www.wintechgeek.com


Report •

Ask Question