IF [NOT] "%username%"=="Administrat
Use the quotation marks around the variables
Don't use the : for the GOTO
Get the Administrator name spelt correctly
Main Topics
Browse All TopicsHi there all,
I'm in the middle of writing a batch job that'll hopefully run an executable ONLY if the currently logged in user is "Administrator"
I've tried this for starters:
IF [NOT] %username%==administrator GOTO :1
However, this seems to stop the batch process and it will not use the GOTO command. What I get as the output is:
%mycurrentusername%==admin
Essentially, I want to parse the logged on user, and use the value it returns to either run the .exe or not
Any help would be much appreciated.
Thanks,
Mike
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I believe your problem is related to the syntax of the command : the brackets mean "optional", what you wanted was actually something like :
IF NOT %username%==administrator GOTO :1
Though, I would suggest to use the /I option (ignore case) of the IF command. So something like :
IF /I "%USERNAME%" NEQ "administrator" GOTO RunIt
should work.
Much good info above - please don't accept mine as i think you don't need more than one of the above,
For future reference on all of MS-DOS's help pages:
Items shown in brackets like [NOT] are optional - but if used the brackets are not included. Since the brackets changed the meaning to DOS, ithe next thing on the line was "was unexpected at this time".
Your original line without the brackets matches the best answer above, except:
I would also aggree that adding quotes is almost always good to prevent problems (like when logging on from a Windows 98 laptop, some variables are not assigned) and i would add them here - but that should not be the cause of your first error above.
My 2¢,
2K
(\o/)
Business Accounts
Answer for Membership
by: DexstarPosted on 2003-12-03 at 14:46:33ID: 9870552
@NYOMSF1:
> Essentially, I want to parse the logged on user, and use the value it returns
> to either run the .exe or not
> Any help would be much appreciated.
Put this in your batch file:
@ECHO OFF
IF %USERNAME% == Administrator GOTO RunIt
GOTO Exit
:RunIt
REM Put command you want to run here
GOTO Exit
:Exit
Hope That Helps,
Dex*