Aravindharaj G
Aravindharaj G

Reputation: 417

How to open command prompt as administrator from address bar

I use address bar of File explorer to open command prompt in current directory(By typing cmd in address bar). It will open the command prompt as Administrator. I have used Windows 7 OS and I logged in as Domain Administrator.

Now I upgraded the OS to Windows 10. Now I am doing the same, But command prompt is not opened as Administrator.(For local Administrator account it was fine). Is there any way to get command prompt as Administrator(Opening from Address bar) ?

Upvotes: 7

Views: 10938

Answers (5)

Stijn Bousard
Stijn Bousard

Reputation: 401

I had the same question, and solved it as follows:

File Explorer's address bar recognizes all .exe and .bat files (and other extensions within the PATHEXT environment variable) that are in path environment variable.

In a directory that is in the path environment variable, e.g. %LocalAppData%\Microsoft\WindowsApps, create a .bat file, e.g. cmdadm.bat with the following content:

set here=%cd%
wscript.exe "C:\...\helper.vbs" "C:\Users\sbo\AppData\Local\Microsoft\WindowsApps\wt.exe" %here% "Command Prompt"

As you can see, you'll need a helper.vbs file (courtesy of https://github.com/lextm/windowsterminal-shell)

helper.vbs:

Set shell = WScript.CreateObject("Shell.Application")
     executable = WSCript.Arguments(0)
     folder = WScript.Arguments(1)
     If Wscript.Arguments.Count > 2 Then
         profile = WScript.Arguments(2)
         ' 0 at the end means to run this command silently
         shell.ShellExecute "powershell", "Start-Process \""" & executable & "\"" -ArgumentList \""-p \""\""" & profile & "\""\"" -d \""\""" & folder & "\""\"" \"" ", "", "runas", 0
     Else
         ' 0 at the end means to run this command silently
         shell.ShellExecute "powershell", "Start-Process \""" & executable & "\"" -ArgumentList \""-d \""\""" & folder & "\""\"" \"" ", "", "runas", 0
     End If

Now you can simply type cmdadm in the File Explorer address bar and you'll get a Command Prompt as administrator in the current directory.

  • wt.exe stands for Windows Terminal
  • "Command Prompt" is the Windows Terminal profile, which is present by default

Upvotes: 0

Alex G
Alex G

Reputation: 1077

Unfortunately a recent Windows 10 Update has removed the Open command prompt mentioned by @Arvindharaj. However, if you feel comfortable editing the Windows Registry then this site that explains how to activate admin cmd right-click option might be a great option. It was for me.

Here are basic steps after launching regedit.exe:

  1. Go to this address: HKEY_CLASSES_ROOT\Directory\shell

  2. Under this folder create a new key and label it runas.

  3. Double-click the runas folder and check if there’s a “Default” key. Right-click it and choose “Modify.”

  4. Once you click “Modify,” the “Edit String” box shows up. Type Open Administrator Command Prompt Here in the Value data box.

  5. Next, in the same folder, create a new string value (right-click the runas folder and choose New and select String Value). Label it as NoWorkingDirectory.

  6. Under the HKEY_CLASSES_ROOT\Directory\shell\runas path, create another key and label it as command.

  7. Double click the folder and you’ll see the Default string value. Right click and choose “Modify.” Under the Value data, enter cmd.exe /k cd %1 and click OK.

FYI - I think this last step is wrong btw. The cmd prompt will launch as admin but in its default folder. So instead enter "cmd.exe /s /k pushd %V" and this should launch the admin prompt in the folder you right-clicked on.

Upvotes: 3

supernova
supernova

Reputation: 3261

Adding up to response from Aravindharaj G :

1> In File Explorer go to the window where you want to open PowerShell / Command Prompt Use HotKey ( ALT (Hold) + F > S > A ) will open PS in that location.

2> Using Top Menu File > Open Command Prompt ( or Open Window PowerShell ) > Open Command Prompt as Administrator > now SELECT

"Add to Quick Access Toolbar"

This will add a Tiny icon in all File Explorer Windows for all.

enter image description here

Upvotes: 0

IFink
IFink

Reputation: 774

I've tried @Alex's solution, but it still didn't work, CMD still evaluated without Administrator privileges. I only have it working after running the following command in command prompt:

> REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
/v EnableLUA /t REG_DWORD /d 0 /f

And restart the Computer after this.

Can't say that this only helps, but maybe this in addition to @Alex's did the job.

Upvotes: 2

Aravindharaj G
Aravindharaj G

Reputation: 417

Screenshot for achieving cmd in Admin mode

We can add this windows default shortcut for achieving cmd as Administrator in single click

Upvotes: 6

Related Questions