views:

1386

answers:

2

I've added this entry into the context menue of an USB stick via autorun.inf:

[AutoRun]
shell\pageant=Activate SSH Key
shell\pageant\command=PuTTY\pageant.exe PuTTY\davids.ppk

Both PuTTY\pageant.exe and PuTTY\davids.ppk are files on the USB stick and should be picked up from there.

When I run this in a shell from the root of the stick it works as intended. But starting it from the menu it tries to load the key from C:\Windows\system32\PuTTY\davids.ppk (checked with Process Monitor).

Trying to use a simple cmd script resulted in this output:

    C:\Windows\system32>cd PuTTY
    Das System kann den angegebenen Pfad nicht finden.

    C:\Windows\system32>pageant.exe davids.ppk
    Der Befehl "pageant.exe" ist entweder falsch geschrieben oder
    konnte nicht gefunden werden.

Is there a way to get this working properly? I guess it should be able to pass the drive letter or get the explorer to use the stick as working directory, but I don't know how. Since I want to use the stick on the go, I'd rather avoid hardcoding my local drive letter.

+1  A: 

It seems it reads "Path" system variable. :( You may add the drive to path but getting the Drive letter is the problem. :-(

Update 1 : You can get the drive letter using a VB script.

Update 2 : Yes, I think you can do that. Check this page.

Update 3 : I tested the script. It works great.

Dim  oDrive
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
For Each oDrive In oFSO.Drives
WScript.Echo "Drive Letter" , oDrive.DriveLetter
WScript.Echo "Drive Type" , oDrive.DriveType
Next

Use some file existance check method to differenciate multiple USB drives.

Chathuranga Chandrasekara
Thank you for your answer, it prompted me to make a few clarifications in the question.
David Schmitt
+2  A: 

I think the easiest solution would be to create a batch file to do this for you. Something named activatekey.cmd like this:

REM switch to the directory containing this script
for %%a in (%0) do cd /D %%~da%%~pa

cd PuTTY
pageant.exe davids.ppk

Place the file activatekey.cmd in your USB stick, and change the autorun.inf to be:

[AutoRun]
shell\pageant=Activate SSH Key
shell\pageant\command=activatekey.cmd
scraimer
That didn't work, see my last edit.
David Schmitt
Hmm, ok - I've edited the script change the directory to be the same as the location of the activatekey.cmd file. I wonder if that will work for you? (I actually got so excited by your idea, that I've already implemented something just like it on my USB stick! Except my solution is a little more complex - allowing to safely remove the stick even after the pageant.exe has executed.)
scraimer