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
Batch file to run cmds only if user is NOT an administrator
Moderator: DosItHelp
-
- Posts: 126
- Joined: 10 Jun 2011 10:30
Re: Batch file to run cmds only if user is NOT an administr
You can use this in XP and Windows 7...
OR
Actually after thinking about it for a few more seconds...
I think this is what you actually want:
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
'
You are mistaken Acy...; Users do not have to be named Administrator for them to be Administrators !
Use wmic, net use or registry.
You are mistaken Acy...; Users do not have to be named Administrator for them to be Administrators !
Use wmic, net use or registry.
Code: Select all
net localgroup Administrators
-
- Posts: 126
- Joined: 10 Jun 2011 10:30
Re: Batch file to run cmds only if user is NOT an administr
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
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
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
-
- Posts: 126
- Joined: 10 Jun 2011 10:30
Re: Batch file to run cmds only if user is NOT an administr
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.