Is it possible to create a shortcut for a relative path in Windows that works as an administrator?

To create a shortcut with a relative path, set the target as follows.

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

It is also easy to make the program run as an administrator.

 Properties > Advanced > Run as administrator 

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

Is there a way to make the shortcut both relative and run as admin?

+17
windows relative-path uac shortcut
Sep 12 '13 at 6:15
source share
3 answers

I did not find an easy way, but it is fine. I was worried that shortcuts with absolute paths were torn between computers. I did not understand that Windows fixes them automatically. This seems sufficient, although relative paths would be more elegant.

Although shortcuts, when created, indicate specific files or folders, they can break if the target is moved to another location. Microsoft Windows has standard algorithms for correcting shortcuts when moving them. Windows 9x versions of Windows use a simple search algorithm to fix broken shortcuts. [1] On Windows NT and the NTFS file system, the unique identifier of the target is stored in the shortcut file, and Windows can use the distributed link tracking service to track shortcut targets, so the shortcut can be silently updated if the target is moved to another hard drive. [four]

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

+8
Sep 21 '13 at 2:42 on
source share

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

Just drop it in the โ€œTargetโ€ of the shortcut properties:

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

Expected Behavior: A short-term CMD window will appear and close immediately before starting chrome.

Note. The Start at: option can be left blank. Also note that the .exe is 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 some time ago.

+1
Mar 13 '17 at 2:53 on
source share

Try:

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

First it changes to a relative path, then the application starts. && - command separator.

In addition, I had to leave "Start In" empty.

Note I did not get this work completely, my application will start, but it will crash. So I can still skip something.

Source

0
Mar 25 '14 at 2:46
source share



All Articles