[Android General] Qui Peccavit:
Running Command Line Tools with Administrator Privileges

.​

COMMAND LINE TOOLS

Open a Command Prompt with Administrator Rights in any Directory​

Whenever modifying the system, be it on Android, iOS or Windows, it is often necessary and usually recommendable to do so with administrative access rights, in order to prevent security prompts in an unfortunate moment while flashing a firmware, or simply to be able to execute critical functions at all. Even in the 21st century, there are actions that can be executed more conveniently and quicker from a Command Prompt (CMD) that looks like an MS-DOS environment, than they could be done under a graphical user interface (GUI). In the previous tutorial, we learned how to add the path to command line tools to the system environment variable, thereby making them available system-wide. Now we want to be able to run them from any location as an administrator, too, to further streamline CMD-based operations.

1.) Adding the option to open an administrator's command prompt to the Context Menu

Paste the following script into Notepad and save it with a ".reg" extension: If your text editing software does not offer .reg extensions, save it as .txt and then rename it to .reg:

Windows Registry Editor Version 5.00
;write minus before to unreg example: [-HKEY_CLASSES_ROOT\Directory\shell\cmdhere]

[HKEY_CLASSES_ROOT\Directory\shell\cmdhere]
@="Open Command Window here"

[HKEY_CLASSES_ROOT\Directory\shell\cmdhere\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdhere]
@="Open Command Window here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdhere\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open Command Window here as Administrator"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="Open Command Window here as Administrator"

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

Double-click the .reg file and confirm to add its content to the Windows Registry.

2.) Set the Application Compatibility Flag

In the same manner as before, create a second registry file to remedy the problem caused by the fact that Windows' native executables cannot be configured via the (in their case non-existent) Compatibility tab under Properties:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Windows\\System32\\cmd.exe"="~ RUNASADMIN"
"C:\\Windows\\SysWOW64\\cmd.exe"="~ RUNASADMIN"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Windows\\System32\\cmd.exe"="~ RUNASADMIN"
"C:\\Windows\\SysWOW64\\cmd.exe"="~ RUNASADMIN"

3.) Tame Windows' User Account Control (UAC)

In case you are the administrator in your company, or when there is no administrator because the machine you are working on is your Personal Computer (PC), Windows' Unnecessary Additional Click (UAC) turns into a nuisance pretty soon, like any security alert that is wrong 99.9% of the time. I will accept any bet that if a malware displayed the UAC dialogue with a text «I am an evil malware that is going to take over your machine and disturb the space-time-continuum as we know it», millions of people will still allow it to continue, simply out of the routine they have been conditioned to on thousands of previous occasions.

To get rid of the time-waster, navigate to %windor%\System32 (for instance C:Windows\System32\ by default), run useraccountcontrolsettings.exe and turn the nerve-killing prompts off.

Unfortunately, sometimes these modifications get overwritten by Windows Update. When that happens, simply repeat the procedure to make executing commands from the Windows Powershell comfortable again.

.