Page 1 of 1
Batch file to run cmds only if user is NOT an administrator
Posted: 01 Aug 2011 21:04
by SpyGob
Hi there,
I'm trying to create a login script that will modify certain registry keys based on the user's credentials. What I want is for the batch file to look for the current user and modify the registry only if it finds that the user is not an administrator. If it finds that the current user is an administrator, then it shoud stop executing commands go to exit.
Any help will be greatly appreciated.
SpyGob
Re: Batch file to run cmds only if user is NOT an administr
Posted: 02 Aug 2011 08:02
by Acy Forsythe
You can use this in XP and Windows 7...
Code: Select all
IF NOT "%USERNAME%"=="administrator" (
Do some commands for users
) ELSE (
Do some other commands
Exit /b
)
OR
Code: Select all
IF /I "%USERNAME%" NEQ "administrator" (
Do your commands for normal users
) ELSE (
Do other commands
)
Actually after thinking about it for a few more seconds...
I think this is what you actually want:
Code: Select all
IF /I "%USERNAME%" EQU "administrator" (exit /b)
Commands for users
Re: Batch file to run cmds only if user is NOT an administr
Posted: 02 Aug 2011 08:17
by Ed Dyreen
'
You are mistaken Acy...;
Users do not have to be named Administrator for them to be Administrators !Use wmic, net use or registry.
Re: Batch file to run cmds only if user is NOT an administr
Posted: 02 Aug 2011 08:53
by Acy Forsythe
Ed you know... You're right
I didn't think about that...
Re: Batch file to run cmds only if user is NOT an administr
Posted: 02 Aug 2011 22:51
by SpyGob
Thank you both for your quick responses.
Acy, what you gave is exactly what I needed. What I actually meant was if the user was the local administrator with the username "administrator'.
Thank you so much. You have taken away a huge headache.
God Bless.
SpyGob
Re: Batch file to run cmds only if user is NOT an administr
Posted: 03 Aug 2011 08:47
by Acy Forsythe
You're welcome SpyGob, but Ed's way is more "accurate" incase you do have users that have administrative rights. This usually occurs in the home/ home office where the first username registered on the PC has administrative rights and in businesses where the "administrator" account is disabled for security reasons, so admin users login with their own username/password.