Automatically Elevate cmd.exe with AutoAdminKey and PsExec
In Windows environments, it is often necessary to run commands with administrative privileges. However, manually elevating privileges every time can be cumbersome. This article will cover a method for automatically elevating cmd.exe system-wide using the AutoAdminKey registry key and PsExec.
Prerequisites
Before proceeding, ensure that you have the following:
- A Windows system
- PsExec downloaded from the Microsoft Sysinternals website
- Knowledge of how to modify the Windows registry
Understanding the AutoAdminKey Registry Key
The AutoAdminKey registry key is a feature in Windows that allows for automatic elevation of privileges for the first command run after a user logs in. The key is located at:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinlogonTo enable automatic elevation, create a new string value named "AutoAdminLogon" with a value of "1". Then, create a new string value named "DefaultUserName" with the username that you want to automatically log in with. Finally, create a new string value named "DefaultPassword" with the password for that user.
Using PsExec for Automatic Elevation
PsExec is a command-line tool from Microsoft Sysinternals that allows for remote command execution. By using PsExec, we can run cmd.exe with administrative privileges automatically.
To use PsExec for automatic elevation, first open an elevated command prompt. Then, navigate to the directory where PsExec is located and run the following command:
psexec.exe -s -i cmd.exeThis command will open a new command prompt window running as the Local System account. Any commands run in this window will be executed with administrative privileges.
Combining AutoAdminKey and PsExec
By combining the AutoAdminKey registry key and PsExec, we can achieve automatic elevation of cmd.exe system-wide. To do this, first set up the AutoAdminKey registry key as described above. Then, create a new batch file with the following contents:
@echo off
psexec.exe -s -i cmd.exe
Save this batch file as "autoelevate.bat" and place it in a location that is included in the system's PATH environment variable. This will allow the batch file to be run from any directory.
Finally, create a shortcut to the batch file and place it in the Startup folder. This will cause the batch file to be run automatically when the user logs in, opening a command prompt window running as the Local System account.
In this article, we have covered a method for automatically elevating cmd.exe system-wide using the AutoAdminKey registry key and PsExec. By following the steps outlined above, you can achieve automatic elevation and simplify administrative tasks in Windows environments.