Jump to content

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


Recommended Posts

Posted (edited)

Hello, Friends

any friend tell me how to run a batch file with admin rights(run as admin) in runonce.

Edited by rehbar

Posted

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.

Posted

Thanks for reply.
Sir my user have administrative right. now how to run a file with administrator rights.

Posted

Sir I want's to run this command with admin rights in runonce.
net accounts /maxpwage:unlimited

how to it possible...

Posted

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

Posted

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.

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...