Blog Examples
Examples for run as administrator from user
Different possibilities to run application with administrator privileges from standard user by RunAsRob and RunAsSpc
Packages of Ninite Installer can install by a limited user without to know the administrator credentials
1) with RunAsRob the part RunAsAdmin
2) or RunAsSpc with administrator login information of administrator in plain text
3) or RunAsSpc with encrypted file and hidden paassword.
Run Powershell script as administrator
First of all, enable powershell script on machine.
- launch C:\Windows\System32\WindowsPowerShell\Powershell.exe from with elevated privileges by right click run as administrator,
- write command >> Set-ExecutionPolicy remotesigned << or >> Set-ExecutionPolicy unrestricted <<
Now there are various ways.
1) Run script as administrator from admin account with elevated privileges.
- Self elevate powershell script is working, by call the same script with elevated privileges inside the script. I am against doing this, because it is the risk to get an endless loop
- or elevate the powershell script by calling the script via another powershell start script, which elevate the main script.
>> Start-Process powershell.exe -ArgumentList '-file c:\test\powershell\pscript.ps1' -Verb RunAs <<
- or create a shortcut to your Powershell script with command PowerShell.exe -Command "& 'C:\Temp\script.ps1'"
and set in the shortut property tab -> Advanced -> Run as administrator
2) Run script as administrator from standard user account.
- Create a shortcut to your Powershell script with command PowerShell.exe -Command "& 'C:\Temp\script.ps1'"
and set in the shortut property tab -> Advanced -> Run as administrator
After start of shortcut, you will be asked to enter administrator credentials.
-
An elegant way to run Powershell script as administrator from standard user and avoid entering the credentials and bypass the UAC is using RunAsAdmin from RunAsRob.
You just have to authorize the script in RunAsAdmin and launch it via RunAsRob.
See following example configuration with a Powershell script >> c:\scrpt.ps1 <<
- Authorize the complete call in RunAsAdmin >> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\scrpt.ps1 <<
- with login option >> as system <<
- Now you can call scrpt.ps1 via RunAsRob and it is running with system rights under standard user account.
>> "C:\Program Files\RunasRob\RunAsRob.exe" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\scrpt.ps1" <<
Run cmd as administrator to get the command line with elevated privileges
Run command line with elevated privileges from administrator account.
- It is known you can right click cmd.exe and select in context menu >> run as administrator <<
- To run cmd as admin directly by double click to avoid a right click and first select the option >> run as administrator <<,
create a shortcut to cmd.exe and set in the properties of the shortcut -> advanced -> >> run as administrator <<
Run command line with elevated privileges from user account.
- use a shortcut to the cmd.exe you have set in the properties -> advanced -> >> run as administrator <<
after double click on shortcut you will asked for the credentials of an administrator
- If you don't want to enter credentials each time use RunAsSpc
>> runasspc.exe /program:"c:\windows\system32\cmd.exe" /domain:"localhost" /user:"admin" /password:"pass" <<
- If you want to hide the credentials use RunAsSpc with an encrypted file
>> runasspc.exe /cryptfile:"c:\tmp\launchCommandLineAsAdminEncrypted.spc" <<
- If you want to hide the credentials and bypass the UAC use RunAsRob, the part RunAsAdmin
and allow cmd.exe to run as administrator from user
Run batch file as administrator
Launch a batch file with elevated privileges from an administrator account.
Create a shortcut of the batch file, select in properties of the shortcut -> advanced -> run as administrator.
Start a batch file as administrator from a user account.
Choose the easiest way and use RunAsRob https://runasrob.com
- Allow the directory of the batch file in RunAsAdmin, a part of RunAsRob
- Start your batch file with command >> "C:\Program Files\RunasRob\RunAsRob.exe" "C:\test\batch01.cmd" <<
- Call this command directly, in a batch file, any script or in a shortcut
Links
Date: 2025-01-09
Data protection
Imprint