# How to Make "Portable" Shortcuts on flash drives.



## azariah007 (Sep 8, 2009)

How many of us have portable software on our flash drives that we have to navigate to through a maze of files? A lot of us right? Well here's a simple tested method that will alow you to do just that. No extra software, no hacks, and, more importantly, no hassle!

PLEASE NOTE: this is was done using Windows XP Home 32-Bit SP3, commands will probably differ for Vista and 7 users. And I haven't been able to verify that the afore mentioned OS's follow the same basic drive letter assinging rules as XP but they should.

1. Plug-in your flash-drive(s). (Don't let any sofware autorun from it/them)
2. a. Go to Start Menu, and click Run...
b. Alternatively Windows Key (between Ctrl & Alt for the uninitiated) + R.
3. Now type in or copy, Diskmgmt.msc
4. This will start the Disk Management Utility
5. Next find your flash-drive (example from my original work, Apacer PortableApps Programs (I: ) )
6. Right-click on it.
7. Select Change Drive Letter and Paths...
8. This will bring up a little window with the drive you selected.
9. Click the Change... option
10. You will be faced by another window with two options. a. Assign the following drive letter, and b. Mount in the following empty NTFS folder. (this last option shouldn't be available and will be grayed out.)
11. Choose a low drive letter in the list, say Z
12. Click OK
13. You will now be faced with a dialog asking you to proceed and warning about loss of information ignore it and click Yes.
14. Your drive will now remount with the new drive letter.

Now you may ask what's so special about this, well this is like IP addresses, your computer is automatically setup so that drive letters, like normal IP addresses, are assigned in order as needed and changed automatically when their are more or less devices. What you have just done is assinged a 'static' drive letter to the device. Any system you now plug into will detect it as drive Z the only problem you could encounter is if you tried inserting this into a computer where there was already a drive Z. But given the chances of a computer with a total of 26 partitions and external devices is unlikely your pretty safe. I forgot server's. Hmm... still.

Next you just create a Shortcut in the ROOT of the drive like you would normally pointing at say Z:\Program Files\7-ZipPortable\7-ZipPortable.exe . Everthing should run like normal in any stystem.

Just another alternative. Their are free portable software sights out their like the one I aluded to earlier where the program runs automatically and indexs your programs in one of its program folders and runs them through itself. Here's the link to Portable Apps.com which is the source I've been using. If you can spare a few dollars be sure to swing them a donation they do a great job.

http://portableapps.com/

Their sofware leaves no traces behind on the host when you close it minus the files you might save to the computers internal hard drive.

Any information additions for other OS's are most welcome. ENJOY!


----------



## Mumbodog (Oct 3, 2007)

Unfortunately this does not work when using it on another PC, this drive letter information is stored in the registry of the PC where you changed the drive letter, not on the drive itself, when plugging it into another PC it will be mounted on the first available drive letter.

The drive letter has to be changed on each PC you use it on.

.


----------



## azariah007 (Sep 8, 2009)

Thank you for that comment I realized this when I plugged it into a third computer. If people have other methods of making "portable" shortcuts please post. For people that repeatedly plug into the same collection of PC's this is still a decent idea I think because it's still a set up once and forget deal for each PC. Non the less I discovered that if you use Paragon Hard-disk manager at least with the hd's I was working with at the time when you assign a letter to partition it seems to be fixed, same with gparted, but non the less I'm not an expert. Check it out any way.

Another thing I noticed is that the affor mentioned PortableApps.com uses a "smart" shortcut which is actually an application that starts the other application any ideas how one would creat such a thing? Without reverse engineering theirs. Please.

I found a sight somewhere refering to being able to just put the name of the drive in instead of the drive letter into the location address in a standard windows shortcut, tried it doesn't work for me. Their is an app on this PortableApps.com sight that is supposably able to generate shortcuts but... I havn't tested it yet. Also you can point a shortcut to the %root% drive in Windows your C: drive so why can't one do this to the root of any other drive? Just fishing here. With all the ideas I've come up with but that my limited to non-existent programing language can't figure out how to write so windows understands.


----------



## DaveBurnett (Nov 11, 2002)

Put this as a command on your flash drive.


```
if NOT EXIST Z:\FILEONYOURDRIVE subst Z: %~d0\
```
 to copy it to Z

and


```
subst Z: /d
```
 to turn it off

Then just run them once.


----------



## azariah007 (Sep 8, 2009)

thanks but... Obviously I enter these in command prompt however... how do make them into auto executable commands just type them in and they auto create or what?

Sorry I'm a hardware wiz so programming is almost non existent in my vocab so a little explanation would be appreciated. Thank you.

By the way I have and do use command prompt a bit (examples <ipconfig> and <ping www.google.com.au>)


----------



## DaveBurnett (Nov 11, 2002)

Use Notepad. Type in the text then save as Z_ON.CMD and Z_OFF.CMD

You MUST run the Z_ON one from the stick as it uses the symbolic % to pick up the "current drive".
Now obviously you can use the same symbolic in short cuts for programs when you start them from the flash drive, but as soon as you move the short cut away from the drive it will cease to work.
That is why you need to have a fixed drive letter.

You could write a batch file that searched all drives for a KNOWN file (like the FILEONYOURDRIVE in my example) and then put it into an Environment variable that you could use when invoking a program.

You could also (and I STRONGLY recommend against this) put the Subst command as an Autorun for when the stick is inserted.


----------



## azariah007 (Sep 8, 2009)

thanks for that. don't worry about even attempting to make them autorun from the USB stick it won't work unless youv'e cracked the Windows firewall so that it autoruns autorun.inf from external devices. to be quiet honest I don't even know how to do it I just know it can be done.

ok notepad, enter commands above and name respectively sweet.

This should assist although not truely automatic it's still viable. now in common English could you explain what those commands mean just for those who would like to know like me.

Thanks for your help.


----------



## DaveBurnett (Nov 11, 2002)

> if NOT EXIST Z:\FILEONYOURDRIVE subst Z: %~d0\


Translates as: If the file Z:\FILEONYOURDRIVE doesn't exist (means you haven't already run it) then SUBSTITUTE Drive letter Z for the drive letter contained in the modified Environment variable %~d0 (which returns the drive letter of the path to the batch file being executed). So if the flash drive is F: the command executed is SUBST Z: F:\

For general help on the SUST command see: http://www.computerhope.com/substhlp.htm

And for details on the details of the Modified Environment Variable:


```
Variable with modifier

Description

%~I	
Expands %I which removes any surrounding quotation marks ("").

%~fI	
Expands %I to a fully qualified path name.

%~dI
Expands %I to a drive letter only.

%~pI
Expands %I to a path only.

%~nI
Expands %I to a file name only.

%~xI
Expands %I to a file extension only.

%~sI
Expands path to contain short names only.

%~aI
Expands %I to the file attributes of file.

%~tI
Expands %I to the date and time of file.

%~zI
Expands %I to the size of file.

%~$PATH:I
Searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, this modifier expands to the empty string.

The following table lists modifier combinations that you can use to get compound results.

Variable with combined modifiers
Description

%~dpI
Expands %I to a drive letter and path only.

%~nxI
Expands %I to a file name and extension only.

%~fsI
Expands %I to a full path name with short names only.

%~dp$PATH:I	
Searches the directories listed in the PATH environment variable for %I and expands to the drive letter and path of the first one found.

%~ftzaI
Expands %I to an output line that is like dir.
```
And the SUBST Z: /d says delete the substituted drive letter Z (the letter NOT the drive)


----------



## azariah007 (Sep 8, 2009)

Thanks again, this certainly is what I've been looking for and you said that the variable %~d0 could be placed in a shortcut instead of the drive letter so long as one didn't move it away from it's file? right?

I'll be setting this up first chance I get you can be sure.

I had found some other forums with this sort of variable suggestion to replace the drive letter but they didn't work and weren't well explained.

Thank you again.


----------



## TheOutcaste (Aug 8, 2007)

One potential glitch; if there is a device using the drive letter (Z: in this case), the *subst* command will fail. You can check if it's being used like this:

```
:: Check if the letter Z is in use
If Not Exist Z:\Nul Goto _IsAvail
:: If in use, see if it's your drive
If Exist Z:\FileOnYourDrive Goto :EOF
::Not your drive
Echo.The Drive letter Z: is already in use by another Device
Pause
Goto :EOF
:_IsAvail
Subst Z: %~d0\
```
I've found it easier to just mount the drive to a folder in the *%SystemDrive%*, that way you don't have to worry about what drvie letters are available.
I use *%SystemDrive%\@~TheOutcasteTools*. Haven't found anyone that has a folder named that yet.

The following batch file when run from the USB drive will determine the current drive letter of the USB drive (*%~d0*), get the Volume Name assigned to that letter via the *MountVol* command, then create the folder if needed, and mount the drive in the specified folder.
It then opens the Shortcuts folder on the drive, which has shortcuts to the tools on the pen drive.
The shortcuts use the *%SystemDrive%* variable and the folder name you choose as the Path to the root of the drive.
For example, if the USB drive is *X:*, and I have *AutoRuns.exe* here:
X:\Tools\Utilities\Autoruns.exe

The shortcut would use *%SystemDrive%\@~TheOutcasteTools\Tools\Utilities\Autoruns.exe* as the path in the shortcut.

The Dismount batch file will dismount the drive, and delete the folder. You could also use Devcon.exe to invoke the Safely Remove Hardware to remove the drive after dismounting, though you have to make sure all windows that access the drive are closed. This means you can't douoble lick a shortcut from an Explorer Window, so I haven't bothered to try that yet.

Devcon is included with Win 7, and can be downloaded for XP. I've not tried it on Vista, but posts on the web indicate it does work in Vista 32 bit versions. I've not tested to see if the harware ID string is the same on different PCs, or varies, as the Volume ID does.

On Vista and Win 7, the mount and dismount batch files must be run as administrator. You can check the box in the shortcut for the Dismount file, but have to right click the batch file/shortcut for the mount file.
I've not tested these extensively, but it works for my thumbdrive on Win 7 x64 and on XP Media Center 2005

The Mount file:

```
@Echo %dbg%Off
SetLocal
"%SystemRoot%\system32\FSUTIL.exe">Nul 2>&1 && Goto _IsAdmin
Echo.
Echo This must be run from an Elevated Command Prompt.
Echo Please right click the %~nx0 file and click Run as Administrator
:_ErrPause
Pause
Goto :EOF
:_IsAdmin
Set _MP=%SystemDrive%\@~TheOutcasteTools
If Not Exist "%_MP%" MD "%_MP%"
MountVol "%_MP%" /D >Nul
Set _CurVol=
For /F "Tokens=*" %%I In ('MountVol /?^|Findstr /L /C:"\\\\"') Do (
  Echo.%%I|Findstr /L /C:"\\\?">Nul&&Set _Curvol=%%I||Set _Drive=%%I
  If %%I==%~d0\ (
    Set _Drive=%%I&Goto _Found
  ) Else (Set _Curvol=%%I)
)
Echo. Error!&Goto :EOF
:_Found
MountVol "%_MP%" %_CurVol%
Echo Volume %_CurVol% mounted to "%_MP%"
Start "" Explorer /n,/root,"%_MP%\Shortcuts"
```
And the Dismount file:

```
@Echo Off
SetLocal
"%SystemRoot%\system32\FSUTIL.exe">Nul 2>&1 && Goto _IsAdmin
Echo.
Echo This must be run from an Elevated Command Prompt.
Echo Please right click the %~nx0 file and click Run as Administrator
:_ErrPause
Pause
Goto :EOF
:_IsAdmin
Set _MP=%SystemDrive%\@~TheOutcasteTools
MountVol "%_MP%" /D && RD "%_MP%"
```


----------



## azariah007 (Sep 8, 2009)

Thanks for the extra info. I mentioned earlier that such an occurance was unlikely but point taken that if someone else was using the same idea and had assign Z as the driveletter it would cause errors. I've hear of the %SystemRoot% trick but hadn't thought much of it I'll definately give it ago thanks.


----------

