You are here

how set path for portable app on stick?

15 posts / 0 new
Last post
ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
how set path for portable app on stick?

Probabaly for most known, but I am a rather newbie to this portable experimenting.

Now trying to set some things like pgp and gpg to work on the stick. They mostly use either some directions for directorires from windows or sometimes a fixed path is OK (like older pgp)
But the stick does no know its root path in advance.

What do I have to enter in possible bat or similar set up file to point the software to its ususal directories if it is no able to search for all in its own dir by defoult?

Kevin Porter
Kevin Porter's picture
Offline
Last seen: 10 years 4 months ago
Developer
Joined: 2007-01-10 19:25
I'm not really sure what you are asking, but

You can use SmithTech's Portable Startup Utility, which has the ability to add a drive letter substitute.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
software like gpg etc

I was trying to set up software like gpg on the portable usb stick.
The software needs either some registry entries to get to its keyfiles or a path env variable to be set.

If all is static on one computer , will work with setting all from some bat file for example, but the path changes every time I stik it to other computer.

so I thozght there might be something like %my usb stick%\apps\gpg or similar expression which I am not familiar with, but will in one go produce valid path for the files needed for the app.

Otto Sykora
Basel, Switzerland

Dagenham
Dagenham's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2007-03-23 06:19
Simple batch file

I guess You need something like this:

set _oldpath=%path%
set path=%path%;[path-to-specific-application]
[specific-application]
set path=%_oldpath%

[Moderator RM: Use PRE for a code block, CODE is for inline code]

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
yes this is true

I just thought there is something existing that will mark some general name for the mobile stik so the path will be updated automaticaly.
Clear, I can read the current value of PATH, then add my app to it and set it back. But for that I need to know the current path of the app on the stik and this is not allways the same. The path to specific application is the problem.
At home it is n:\something at work it is f:\something on the laptop h:\something

I thought there might be some general expression for 'my usb stick' or so, but as I am new to this , I probably see the things toosimple.

Otto Sykora
Basel, Switzerland

BuddhaChu
BuddhaChu's picture
Offline
Last seen: 3 days 22 hours ago
Joined: 2006-11-18 10:26
%~dp0

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
"%~dp0"

OK will first read all the threads , but in general do I understand:

if my path to gpg is:
N:\gpg\gnupg
or
F:\gpg\gnupg

both being on the stick, but on different computers

then
I can make a bat or from command line say:

SET GNUPGHOME=%~dp0\gpg\gnupg

and this will be the same as when I type under cmd
SET GNUPGHOME=F:\gpg\gnupg

Is the "%~dp0" meaning for all portable drives or what does it means really?

Otto Sykora
Basel, Switzerland

BuddhaChu
BuddhaChu's picture
Offline
Last seen: 3 days 22 hours ago
Joined: 2006-11-18 10:26
The value of that variable

The value of that variable "expands" into the drive letter it was called from.

Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
~dp0

Oh I see:

so I have to have it a .bat let say on the root of the stick beeing the N:\ drive currently

in the bat I say
SET GNUPGHOME=~dp0\gpg\gnupg

when I run the bat from that stick
the variable GNUPGHOME will become N:\gpg\gnupg

is this what is meant to do it?

Otto Sykora
Basel, Switzerland

rab040ma
Offline
Last seen: 12 hours 30 min ago
Joined: 2007-08-27 13:35
that should do it

Remember that the environment variable is set just while that .cmd file is running; after you exit from that CMD window, the variable is gone.

However, programs you launch from the CMD file after you set the veriable will inherit the variable.

I believe the ~dp0 trick only works on more recent OS versions. To be compatible with older ones, you might want to make a quick NSIS launcher that sets the variable then launches something, e.g. CMD.exe or PAM, which would then inherit the variable and pass it along to everything launched in turn.

MC

rab040ma
Offline
Last seen: 12 hours 30 min ago
Joined: 2007-08-27 13:35
home

If I recall correctly, GPG will look in the %HOME% environment variable, which is why I suggested in another post that PAM set it. That way all the programs PAM launches would inherit that environment variable and be able to find your key. If there is another environment variable that is more specific to GPG, you could do the same thing with that.

The trick is to set the environment variable so PAM and everything it launches inherits it. I think SmithTech's program might be able to do this, or you could make a launcher for PAM and use that (e.g. replace StartPortableApps.exe). The launcher could detect the drive letter for the current PA drive and set it into the %HOME% (or whatever) environment variable before launching PAM. Then PAM should automatically pass it on to the programs it starts. Things launched the normal way (from the start menu, for example) would not see the same environment, so no cleanup would be required ... but it would also mean that it would be difficult to use GPG from one of those programs. But you'd only be using GPG in your PA programs anyway, right?

Does that make sense?

MC

LOGAN-Portable
LOGAN-Portable's picture
Offline
Last seen: 11 years 5 months ago
Developer
Joined: 2007-09-11 12:24
Shortcuts update

I used to have a few shortcuts on the root of my stick. I was surprised they seemed to update themselves whenever the driveletter changed after clicking them. Having the shortcut on the pc is another story however Smile

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
~dp0 or ~d0 ?

first I have seen that those two expressions are used , so which one means what?

Then:
I am trying to set up something with gpg or pgp, both use einter env varaiable or in recent versions also registry.

OK, I thought allways that when I set a env variable that this will stay so until removed or so. ?? I am confused.

GPG for example needs apparently some GNUPGHOME I understand , PGP needs PGPPATH to point it to the place where the binary is.

However, in the case of pgp, it seems that one can place the keyrings into PGPPATH and it will find them, but in the case of gpg, there is other place for keyrings and the .conf file for it. Under windows this will be the in the users profile path, but this can be changed only temporary in command line with the --homedir which does not remain, so each time some command is given this must be defined before, which makes it complex, since one can give the absolut path in such case as well.
Front ends have often no way to set all that, they use defoult values, that means windows path to own profile...

the enigmail/thunderbird solution takes care of it, but also here the path to the keys seems to be fixed relativ to the binary. This does then not work when the keys are placed in othe dir, e.g. truecrypt protected container or similar.

Otto Sykora
Basel, Switzerland

rab040ma
Offline
Last seen: 12 hours 30 min ago
Joined: 2007-08-27 13:35
variables

first I have seen that those two expressions are used, so which one means what?

The easiest way to see what they mean is to make a test cmd file and try them.

echo %~d0%
echo %~dp0%
set GNUPGHOME=%~dp0%home
set HOME=%~dp0%home
echo %GNUPGHOME%
echo %HOME%

The "0" refers to the cmd file itself.

The ~d is the drive letter and the colon for where the cmd file is.

The ~dp is the drive letter, colon, and the rest of the path.

The trick with environment variables is that they are inherited by programs from whatever program started them. If you set the environment variable in a cmd window, then run a program (e.g. gpg) it will "inherit" its environment from that window (and sub-windows inherit from their parent, and so on). But other windows and programs not started from that cmd window won't inherit that environment variable. That's why it is good to set the environment variable "upstream" of the programs you want to use it. So if you set the environment variable in a cmd window, then run e:\StartPortableApps (substituting whatever your drive is) from the same command window, Portable Apps and everything you start from Portable Apps should inherit that environment variable. Then you can use "--homedir=%GNUPGHOME%" or whatever and get the right path -- or GPG will just read it out of the environment!

If you try setting it manually and figure out what works and what doesn't, you might understand some of the options that have been suggested. I realize that you want to automate it eventually, but running it manually can help you see what is going on or what steps the automation needs to take.

Are you running GPG from a command window or CMD file, or doing something else with it?

By the way, these are the variables that GPG knows about:

HOME
    Used to locate the default home directory.
GNUPGHOME
    If set directory used instead of "~/.gnupg".
COLUMNS
LINES
    Used to size some displays to the full size of the screen.
LANGUAGE
    Apart from its use by GNU, it is used in the W32 
    version to override the language selection done 
    through the Registry. If used and set to a valid 
    and available language name (langid), the file with 
    the translation is loaded from 
    gpgdir/gnupg.nls/langid.mo. Here gpgdir is the 
    directory out of which the gpg binary has been 
    laoded. If it can't be loaded the Registry is 
    tried as a fallback.

It may not be obvious, but one thing this means is that if %HOME% is set, GPG will look for .gnupg directory in it. But you could use %GNUPGHOME% in order to avoid having to try to make a directory that begins with a period (which you can do from a command prompt).

If the environment variable is set, you don't have to do the --homedir command line thing.

Figuring out where the Truecrypt volume is might be a bit of a chore; better to start everything (or at least your CMD script) from within the Truecrypt volume.

MC

ottosykora
Offline
Last seen: 7 hours 39 min ago
Joined: 2007-10-11 17:48
thank for ~dp0 explanation

OK I will try all that slowly step by step then I will dicover all the details.

I am at present just dicovering how the gpg works, have used pgp for many years, somehow got into problems to run it from portable, therefore want to educate myself on gpg first.
It works with the TB and enigma so far, but I want to use ist with some GUI frontends, even some of the old windows3.1 frontends might work, but they all will relay on automatic operation from env variables and path settings in minimum.

In pgp we used to set the path to the exe in PATH and PGPPATH to the keyfiles. In gpg all is similar but different enough to confuse me.
After all gpg has lot of linux traces in it, while pgp was dos based in its original.

Otto Sykora
Basel, Switzerland

Log in or register to post comments