Για τους μη αγγλομαθείς, θα ακολουθήσει και ελληνικό κείμενο
For quite some time, i was wondering if there was an easy way to have relative path shortcuts in windows – for use on usb sticks, external drives, etc.
The problem starts when you have a program you need to run from your usb stick – but while inserting it on other computers, the assigned letter changes, therefore the path also. Windows work on an absolute path (ie F:\Program Folder\Program.exe) but the F:\ part on someone else’s computer may become D:\ or E:\ – and that will be ruing the shortcut.
While doing a research on the mighty Google, i came up to hard answer: While many people had tried, relative program shortcuts seemed not possible.
Others, used two or three programs to make it work, but this was not a plug-and-play; others, created programs to run relative path shortcuts.
But yesterday, i had a small idea: how did my computer know where is the notepad program? The question is not all that simple, because due to a bizzare installation, my local drive is not the normal C:\ but F:\
Well, all i had to do was look the shortcut of the program. Right Click on the icon, Properties, and i was right. The program was not located on C:\ or F:\ but on a %SystemRoot% variable.
I was on to something. What did the variables do? Well, i just had to ask Wikipedia: http://en.wikipedia.org/wiki/Environment_variable
Now, my usb program was not in %SystemRoot%, nether in %SYSTEMDRIVE% – those were variables locating to absolute paths. So?
Well, i start looking around for other variables. And the %path% variable seemed quite to the place. While it does not say anything like that on the manuals, i thought that the %path% variable would return the actual path of the shortcut. So, if i used that plus the location from the shortcut to the program, it would work regardless in which folder or drive the shortcut was placed.
So, i’ve created a shortcut for my program, I’ve put it on the root of my usb drive, then went to its properties (right click, properties) and changed the ‘Start In:’ location from D:\Program File\ to %path%\Program File\Program.exe (note that i added the ‘program.exe’)
When i tested the usb on an other computer, with a different drive letter, the shortcut worked like a charm 🙂
The obvious drawback here is that you need to keep the path from the shortcut to the program intact. But, other than that, you can put the joined shortcut and program everywhere you want – it will keep on working.
Nice?
So, here is my small contribution to the world: you CAN create shortcuts to programs with relative path, with just a minor tweak!
PS: If you wish to comment, don’t forget to put the number twelve in the box that asks «Απάντηση»


(11 ψήφοι, βαθμολογία: 4,82 / 5)








