33

I have a shortcut to a program that only works when run as administrator but in the shortcuts advanced options "always run as administrator" is greyed out. I've looked at the other similar questions but none apply to my issue. UAC is enabled, I am an administrator and i have no idea how to run it in cmd.

Hennes
  • 65,804
  • 7
  • 115
  • 169
man-qa
  • 367

12 Answers12

16

It works if you add the executable to the shortcut target. For example:

Right-click on the shortcut and change the target from:

C:\Scripts\helloworld.js

to

wscript.exe C:\Scripts\helloworld.js

(or)

cscript.exe C:\Scripts\helloworld.js

Then the Run as Administrator checkbox is activated in properties.

Eg:

for a python script add in the target field:

"C:\Users\......\Python36\python.exe" "C:\Users\......\test.py"

For PowerShell script add this in the target:

powershell.exe -command "& 'C:\A path with spaces\MyScript.ps1'"

(if you want to also pass some args see this)

Don't forget to check the "run as admin" after...

All the glory to Ramesh Srinivasan

JinSnow
  • 912
8

You may be able to use the run as administrator available on the compatibility tab.

One way third party way would be with nircmd. http://www.nirsoft.net/utils/nircmd2.html#elevate

4

It seems as though the "run as administrator" context menu option and/or shortcut checkbox are unavailable for batch files/scripts. This was answered for PowerShell here: How to run script as administrator?

I don't have an answer yet for running a common batch file.

2

This seems to happen with file types windows doesn't recognize/trust. But I just found a simple solution for this.

Make a shortcut to cmd.exe (c:\windows\system32\cmd.exe), and replace the Target field with this

C:\windows\System32\cmd.exe /c start "" "c:\path\to\your.file"

Now you should be able to enable the "Run as administrator" on the Advanced tab

Caveats:

  • On windows 10, running as administrator seems to have a different set of network drives, try to use absolute UNC paths rather than mapped drives
  • If you need to pass parameters please check here for some documentation for the Start command

Why do we use Start instead of just opening it with cmd.exe?

  • If you just run the file using a shortcut to cmd.exe /c c:\path\to\your.file, you're stuck with an empty black window open so long as your program is running

How does using Start work around this?

  1. It starts a cmd instance with the /c flag which closes it after it's command finishes running
  2. It then runs Start which is a native command in cmd.exe that opens a "program" in a new window
  3. The way the Start command works if it's not an executable the launch gets passed up to Windows, which then opens it using the associated program for that file type
  4. Once the launch is started, the Start command ends which then lets the cmd.exe window close
2

This seems to happen when a shortcut points to an object identifier rather than a directory path.

You can tell if this is the case because the target in the shortcut properties is something like {0AFACED1-E828-11D1-9187-B532F1E9575D} instead of a directory path.

If you want to create a shortcut to something in C:\Windows\System32, create the shortcut directly off an item in that folder, rather than trying to create it from an existing shortcut on the start menu.

Giacomo1968
  • 58,727
1

The fix is to create a shortcut to the executable that needs to be run as admin (if you want to workaround the ugly code for invoking the UAC prompt). After creating the new shortcut, right-click on it and select Properties, then click the Shortcut tab, then the Advanced... button and finally check the Run as Administrator checkbox.

drws
  • 113
BrianD
  • 21
1
  1. Go to the properties of shortcut file
  2. Click on shortcut tab
  3. add "powershell.exe" before the path of file in Target

it should look like below:

powershell.exe -file "H:\Powershell\MyPoshScript.ps1"

  1. Click apply
  2. Click advance button
  3. Run as administrator now selectable.
  4. Check Run as administrator and apply --> OK

Done

reference from: How to run script as administrator?

Milansinh
  • 11
  • 1
1

This is the solution (example for Word 2016, Windows 10)

  1. Don't use the regular shortcut
  2. Find the main file (for Word 2016 : "C:\Program Files\Microsoft Office\Office16\WINWORD.EXE")
  3. Make a shortcut with "Send to the desktop as a shortcut"
  4. Now you will see that "Always run as an administrator" option is not greyed out.
ZygD
  • 2,577
Tuncay
  • 11
0

I had this issues on a Windows Server 2008 R2 SP1 system when running shortcuts to run batch files/VBScripts to sync and eject USB disks, or to shutdown Hyper-V systems in preparation for staff to reboot the server cleanly.

Found when I right-clicked the icon, selected properties, then selected the Advanced button next to Change Icon. Select the Run As Administrator option then Save. If UAC is enabled, it will still ask for permission to run, but it will now run properly.

Larssend
  • 3,971
Denis
  • 11
0

My icon was copied to the quick launch bar. The option to run as administrator was greyed out. So I started again and I deleted the shortcut i had previously tried to set.

This is how i solved the issue.

Opened my start menu, found the icon I wanted, properties, open file location. (This opened the file location of the shortcut from my start menu - perfect).

Now I selected the shortcut icon and copied it.

I then right click on my quick launch bar, "Open Folder" and pasted a copy of my shortcut there.

Now I have access to set it to run as administrator.

Valamas
  • 1,555
  • 6
  • 28
  • 44
0

BrianD gave the best answer and Ross in How to run script as administrator? explained it:

Instead of using the compatibility tab (where the option is greyed out ) use the Advanced button on the Shortcut Tab

This is valid for Windows7 at least.

user3603546
  • 194
  • 1
  • 5
0

I was trying for Control Panel to "Run as admin", but it was greyed out for a standard user. Solved by opening C:\Windows\System32, right-clicked on Control and created the shortcut on the desktop. Now this shortcut is available with "Run as administrator" on right-click.