You are here

Directory For USB Drives

16 posts / 0 new
Last post
Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
Directory For USB Drives

Hey, I was wondering if anyone knows a way to type a directory which points to the current USB drive, regardless of which actual Physical Drive Letter any given Computer assigns it

For example, I want to create a Shortcut to a file, but as soon as you move to another computer where the USB is assigned a different letter than the letter it was created on, the Shortcut no longer works

For instance, when I create a shortcut pointing to:

I:\My Portable Programs\Apps\Cool Program.exe

will not work on a computer where I plug it in and its F:\, since the address is no longer pointing to anywhere that exists on that computer

can I do something like %dir%\My Portable Programs\Apps\Cool Program.exe or something similar to make the shortcut always work when its launched from its own current directory where it currently resides?

i suppose this must be common in Portable programs, or else it'd be hard to get them to work on all computers

thanks for any help

darksabre76
darksabre76's picture
Offline
Last seen: 3 months 3 weeks ago
Developer
Joined: 2011-04-19 23:28
Well...

Well, the way that the launcher works, it takes into account a few special Environment variables that are unique to the launcher. You can find a list of them here. The vast majority of them won't work in normal shortcuts, so keep that in mind. If you're planning on making a program even semi-portable, it might be better in the long run to use the launcher since it's a little more versatile.

Bennieboj
Bennieboj's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2010-09-16 07:28
Depends

Depends on the location of the shortcut:

  • If the shortcut is on your usb drive:

    1. Using a batch script (simply put the path on your us drive inside the .bat file)
    2. Using Relative
  • If the shortcut isn't on your usb drive: You can probably make a script (batch, ahk, ...) to check if a certain path exists:
    • D:\My Portable Programs\Apps\Cool Program.exe
    • E:\My Portable Programs\Apps\Cool Program.exe
    • F:\My Portable Programs\Apps\Cool Program.exe
    • ... till Z:\My Portable Programs\Apps\Cool Program.exe

Yes, I set the working directory!

Grantwhy
Offline
Last seen: 11 months 3 weeks ago
Joined: 2010-07-28 22:05
Batch File answer

If you are willing to use a Batch File, in the past I made a batch file that did what you are after. (ran a program regardless of changes to the drive letter)

If I understand my Batch file correctly (I copied and pasted from the 'net and it works [on XP SP3 computers], but I'm not 100% sure why :-p)

using your example (I:\My Portable Programs\Apps\Cool Program.exe)

a batch file (on the same USB Drive) containing

set drive=%cd:~0,3%
echo %drive%

"%drive%My Portable Programs\Apps\Cool Program.exe"

should launch Cool Program.exe no matter what the drive letter is.

note: if the folders/file name contain a space you *DO* need to put the " at the beginning and end of the line.

That batch file will leave a dos window open while the program is running. (well, it does for me)

The way I've found to get the dos window to close is to use START command.

set drive=%cd:~0,3%
echo %drive%

start "" "%drive%My Portable Programs\Apps\Cool Program.exe"

Yes, the "" between start and %drive% is necessary.

Please be aware that START is also use to run multiple programs in a batch file at the same time (batch files, when starting a programs this way, will wait until the first program closes before running the next one)

ps: one other fun thing I did with my batch file was use a 'BAT to EXE' converter program to turn it into an EXE file, which the PortableApp Menu will recognise and add to its list of programs :-). The only downside to this is every so often an anti-virus program with detect one (at random it seems) of the BAT>EXE files I've made as a threat and delete it Sad

apologies if that doesn't work for you or if I have explained it badly.

Good luck Smile

Bennieboj
Bennieboj's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2010-09-16 07:28
Just for future reference

The %drive% variable ain't necessary, you could also use relative paths (it starts from the current working directory or you could use %~dp0).
Also, this only works if the bat file is located on the same drive as the program.

As for your batch file (since you didn't understand what it did...):

REM everything that starts with REM is a comment :)
REM sets the "drive" variable to the drive part of the path (d:\, e:\, ...)
set drive=%cd:~0,3%
REM prints the drive to the command line, you can remove this if you want.
echo %drive%

REM start has 2 required parameters, the window title and the path.
start "" "%drive%My Portable Programs\Apps\Cool Program.exe"

Yes, I set the working directory!

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
thanks guys so I guess

thanks guys

so I guess Relative & Batch files are both good ways.. but then there's inherently another problem with both..

the Icon itself is lost when the drive changes as well

anyone know how to keep the original Icon?

can you use the Launcher to install any stand-alone program, like a stand-alone.exe portable program, in a quick & simple way?

or use the launcher just to install a shortcut to a program?

or is there any program that just handles shortcuts & their respective icons?

I REALLY dont want to change all my icons to default windows system icons

Thanks

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
Well, I used "Bat to EXE" & "Pstart"

Well, I used "Bat to Exe" which allows you to bundle an Icon file & create an *.Exe file from a Batch file...

I didnt get it to work with a simple:

My Portable Programs\Apps\Cool Program.exe, as the program suggests..

but when I made the batch which u guys suggested:
-----------------------
set drive=%cd:~0,3%
echo %drive%

start "" "%drive%My Portable Programs\Apps\Cool Program.exe"
-----------------------
it worked, but the dos window popped up for a second.. not a big problem

@benniboj: what do you type exactly if %drive% isnt needed?

can you post an example of a script that would keep the window closed?

anyway, its a great solution to create shortcuts while keeping the Icons, so I'm happy with it

also, theres a portable program called "Pstart" which installs portably to your USB drive, and allows you to browse or search for .*exe files on your USB drive to create a custom menu filled with any number of your programs, whether they installed from the portableapps.com platform or not

so thats a pretty cool way to go as well..

Bennieboj
Bennieboj's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2010-09-16 07:28
Code + no BatToExe

This is what I have: start "" FreeFileSyncPortable\FreeFileSyncPortable backup.ffs_batch

You can go back to the root of the drive using "..".
So
start "" ..\folder\awesome game.exe opens J:\folder\awesome game.exe
if the bat file is located inside another folder of the drive
(like e.g. J:\myshortcuts).

Also: BatToExe programs useually use UPX to compress the exe. This is mistaken for a false positive most of the time, so I don't use these programs anymore. Just so you know, your exe might get deleted.

Yes, I set the working directory!

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
what do u mean

-------------
QUOTE::: This is what I have: start "" FreeFileSyncPortable\FreeFileSyncPortable backup.ffs_batch
-------------
what do you mean, "thats what you have"? is that an example of a file you are using? what is *.ffs_batch?

-------------
QUOTE::: You can go back to the root of the drive using "..".
So
start "" ..\folder\awesome game.exe opens J:\folder\awesome game.exe
if the bat file is located inside another folder of the drive
(like e.g. J:\myshortcuts).
-------------

you say: "..".
But you type: "" ..\

what does that mean? why are you saying two completely different things there?

and are you saying "" ..\game.exe will find the game.exe file in any folder on the USB drive, no matter how many levels down it is in the folder structure?

-------------
QUOTE::: Also: BatToExe programs useually use UPX to compress the exe. This is mistaken for a false positive most of the time, so I don't use these programs anymore. Just so you know, your exe might get deleted.
-------------

and what do u mean "Mistaken for a False Positive 'Most of the Time'"?

what/who would delete the exe file? do you mean in antivirus programs?

I dont delete anything automatically, and I believe all of the computers I use dont either.. I'm not required to scan my entire USB before I use it, since I mostly use them on Ghost OS's which are in no way affected by any viruses anyway... so i think it'll work.. I suppose maybe you could rename the file from .exe to .abc or something until after the scan, not sure if that'd work though or is worth the trouble

anyway, thanks for the input

Bennieboj
Bennieboj's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2010-09-16 07:28
Hope this clarifies

1) Yes, that's an example of how I use it in real life. The *.ffs_batch is a command line parameter that I pass to FreeFileSyncPortable, it's just an example. If your program doesn't need any command line parameters, ignore this. Also it doens't have anything to do with a *.bat file Smile

2) What I should have said is this: You can go one level up in the hierachy by using two dots (..). Eventually you'll end up at the root of the drive. I only put the quotes around it to make it clear but apparently it confused you, sorry.

start command    window title   command       parameters
start            ""             path          -example

In here, the path can contain the double dots, like in my example with FreeFileSync.

and are you saying "" ..\game.exe will find the game.exe file in any folder on the USB drive, no matter how many levels down it is in the folder structure?

If you understood what I just said, this question should be irrelevant Biggrin

3)Yes, I meant antiviruses. Not all antiviruses are equally forgiving nor user friendly Also, just by renaming a file, it'll still get deleted. You might not be able to use your programs on a public pc or a pc with another antivirus.

Yes, I set the working directory!

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
well, you'll still be able to

well, you'll still be able to go to the directory and click the original .exe file anyway, if you have to.. but its nice to not have to when you dont have to.. anyway, i quite like Pstart as well.. it takes some time to get set up, and grouped, and get rid of executables you dont need, and add all the ones you do.. but once you do that, it has a back-up function, and looks right good..

In here, the path can contain the double dots, like in my example with FreeFileSync.

well, i tried your method but I kept getting errors

are you saying you can put as many double dots as you want? and that: ...... would go up 3 levels?

anyway:

set drive=%cd:~0,3%
echo %drive% start "" "%drive%My Portable Programs\Apps\Cool Program.exe"

works right well

thanks

Bennieboj
Bennieboj's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2010-09-16 07:28
Yes, you could just click the

Yes, you could just click the exe, but OP asked for a "shortcut like" solution Smile

Never used Pstart...

..\..\..\ Goes up 3 levels. It's basic command line logic (ms-dos on windows), google it, you'll learn a lot Smile

Yes, I set the working directory!

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
well, at any rate, I live in

well, at any rate, I live in a region where practically nothing in the entire country is set to ever delete anything automatically, due to various political reasons..

so I am not likely to ever find a computer that would invade my USB & permanently delete anything it wants to.. which i'm thankful for..

in fact, there's only a couple programs that are set to do that by default, Microsoft Security Essentials, & Norton AV are two that come to mind, and I'd never use either, neither would any IT / Admin guy in any company or location I've ever been.

And, as I mentioned, most computers have Ghosted all Drives anyway, so you can never leave a byte of your own information on the computer anyway.. they dont care if you upload viruses all day long...

and the ones that dont ghost everything, have the good sense not to allow invasive quasi-AV programs to destroy files for unrelated Private Corporate Interests & what not..

Since most AV's which destroy files permanently by default are created as such to rid the world of perceived pirated material, keygens, cracks and other such stuff... so there's an inherent conflict of interest between a users Private Files & and certain AV's ulterior agenda.. and any IT guy worth his salt would definitely not have any such AV installed. at least I've never met one or a come across a properly administrated computer which does..

but thats me, i have no idea what / where you find them in play or where you use computers.

but anyway, so ya, this solution works absolutely GREAT for me, and probably will for most people on the planet. I'm VERY happy to have found this method of Creating Shortcuts & retaining their Icons on Relative Paths for Portable Storage Devices

and thanks for the information on batch scripts.. but, seriously, if I put every one of your posts together, I still would not have enough information for a single example of a working Batch script..

maybe you can just give the entire batch script that you believe works, from start to finish, for a file located at J:\My Portable Apps\Games\Cool Game.exe - otherwise, thanks anyway

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
Shell Execute

Anyone know how to / if you can can use Shell Execute from a USB ?

I tried:
set drive=%cd:~0,3%
echo %drive%

start "" "%drive%Portable Apps\ShellExecute.exe /F:start "Portable Apps\Start.exe" /R:hidden

but that didnt work, something wrong with the syntax maybe, a DOS windows launches, but something wrong with the location to Start.exe..

thanks

Grantwhy
Offline
Last seen: 11 months 3 weeks ago
Joined: 2010-07-28 22:05
odd number of "

at a guess, the problem is you have a odd number of " in the line.

one before %drive%
one before Portable Apps\Start.exe
and one after Portable Apps\Start.exe

I'd try taking out the " before Portable Apps\Start.exe and see if that works.

and if it doesn't I'd put it back and add a " after /F:start

ps: if you add a line in your batch file that says

pause

it will wait for you to push a key before it continues. I have found that a good way of looking at error messages when I make BAT files. (and then take it out when I am happy with the BAT)

I hope that helps Smile

Tenzen
Offline
Last seen: 5 years 3 months ago
Joined: 2013-04-07 21:04
it seems the problem is in

it seems the problem is in the bat file itself

shellexecute is designed to run via cmd line.. and your program would need to have that function in order for it to launch hidden..

meaning, Bat files dont do that.. they need to pop up a window before accessing the Command Line..

you'd need a program that allows access to cmd, might look a bit like Pstart

or you'd need to use VB to program a shellexecute command, bundle the icon, and pack it as an exe file.. like writing your own program..

it'd be cool if there was a program tat could do that

Log in or register to post comments