Jump to content

how to run a batch file as "run as admin"


rehbar

Recommended Posts


RunOnce will execute under the current user context at logon. Without using something else to execute the file, you will need to invoke the rights within the .cmd file itself.

There is the runas command, which you can specify a different user account to run a command with, but I believe you cannot script in a password. So it would only be useful for an account in the Administrators group (or custom group with appropriate permissions) that did not have a password on it.

You should look into use Task Scheduler instead. There is more freedom to setting up the condition that way. You can say, when x user logs on, run this program as this other user.

Link to comment
Share on other sites

You can try, making a shortcut to:

C:\Windows\System32\cmd.exe /c "net accounts /maxpwage:unlimited"

give it adminrights, and place it in Autorun Folder...

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

Link to comment
Share on other sites

You can also disable password expiry with wmic, but the command needs the user account name:

wmic useraccount where "name='Support'" set PasswordExpires=false

I use a command like that in a .cmd I run in FirstLogonCommands for custom deployments.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...