[Bat] How to execute commands and batches with administrator privileges!


Hello!This time, I will summarize a little how to execute a batch file with administrator privileges.

Use the Runas command

First, I will simply introduce the commands provided at the command prompt.

runas / user: [administrator account name] [process you want to execute]

This method requires you to have an account with administrator privileges and enter the password after running this command.
In many cases, you have to ask the user to enter it, so it can be a bit difficult to get the user to do it.

However, since the user is specified firmly, it is effective when complicated permission settings are set in Active Directory etc.

runas / savecred / user: [administrator account name] [process you want to execute]

You can also memorize your credentials by adding the / savecred option.You only have to enter the password once at the beginning, and you can omit the password after that.

The Runas command is effective when you want to execute with an account that has system-wide authority rather than administrator authority for one terminal.

Use PowerShell

For some reason, PowerShell has commands that you can easily execute with administrator privileges.
This is very useful because you don't have to prepare the password and account as before.

powershell start-process [process you want to execute] -verb runas

The processing executed by this command is executed with administrator privileges of the terminal.
Since there is no need to specify an account or enter a password, it is very easy to execute with administrator privileges. (Although a pop-up due to User Account Control appears ...)

Since 10 of Windows 1703, it has become a little troublesome to execute the command prompt as an administrator. (Until 1607, it was easy to start by right-clicking the start button)
It is also a trick that you can easily execute the administrator by batching the following commands.

powershell start-process cmd -verb runas


The Runas command is effective when you want to execute it as a user with system-wide administrator privileges.
With PowerShell, it's very easy when you want to run with administrator privileges for each device

Both are decided on a case-by-case basis.
There are other administrator execution methods, but I think it is safe to solve this problem first.

I hope it helps you.


Translate »
I copied the title and URL