Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a shortcut to a relative path in Windows that runs as admin?

To create a shortcut with a relative path, set the target to the following.

%windir%\system32\cmd.exe /c start your_relpath\app.exe [your_args] 

It is also straightforward to make the program run as administrator.

Properties > Advanced > Run as administrator 

But putting the two together doesn't work. When cmd.exe is started as admin, it loses the current working directory and goes to %windir%\system32. The relative path starts there which is not intended.

Is there any way to make a shortcut that is both relative and run as admin?

like image 938
Trevor Merrifield Avatar asked Sep 12 '13 06:09

Trevor Merrifield


People also ask

How do I create a path to shortcut?

Make a new shortcut to: cmd.exe /c start. Now right-click on it and get properties of the shortcut (shortcut tab). The full shortcut path should have been set to this: %windir%\system32\cmd.exe /c start .

Where are shortcuts located in Windows 10?

To view the location of the original file that a shortcut points to, right-click the shortcut and select "Open file location." Windows will open the folder and highlight the original file. You can see the folder path where the file is located in the top of the Windows Explorer window.

What is start in shortcut?

In a shortcut, the "Target" points to the executable file; 'Start In' points to a directory that the executable /might/ use. as a default starting directory that you would see in a. "File Open/Save" dialog.


2 Answers

I didn't find an easy way but that's fine. I was concerned that shortcuts with absolute paths would break between computers. I didn't realize that Windows corrected them automatically. This seems sufficient, though relative paths would have been more elegant.

Although shortcuts, when created, point to specific files or folders, they may break if the target is moved to another location. Microsoft Windows has standard algorithms for fixing up shortcuts when they are moved. Windows 9x-based versions of Windows use a simple search algorithm to fix broken shortcuts.[1] On Windows NT-based operating systems and the NTFS file system, the target object's unique identifier is stored in the shortcut file and Windows can use the Distributed Link Tracking service for tracking the targets of shortcuts, so that the shortcut may be silently updated if the target moves to another hard drive.[4]

http://en.wikipedia.org/wiki/File_shortcut#Microsoft_Windows

like image 56
Trevor Merrifield Avatar answered Sep 21 '22 01:09

Trevor Merrifield


For a portable shortcut, that works with a relative path, use the following:

Simply drop this in the "Target" of the Shortcut Properties:

%COMSPEC% /C "start GoogleChromePortable.exe -enableextensions -incognito" 

Expected behavior: A brief CMD window will popup and close just prior to chrome launching.

Note: the "Start in:" option can be left blank. Also note, the .exe is located in the same folder as the shortcut, but move the folder and the shortcut works just fine.

This is confirmed to work in Win10 1607.

Credit: some other post on stackoverflow a while ago.

like image 33
semtex41 Avatar answered Sep 23 '22 01:09

semtex41