autorun.inf:如何获得驱动器号?

时间:2021-12-20 22:40:41

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

我已经通过autorun.inf将此条目添加到USB记忆棒的上下文菜单中:

[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.

PuTTY \ pageant.exe和PuTTY \ davids.ppk都是USB记忆棒上的文件,应该从那里拿起来。

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).

当我从棒的根部运行它时它按预期工作。但是从菜单启动它会尝试从C:\ Windows \ system32 \ PuTTY \ davids.ppk加载密钥(使用Process Monitor检查)。

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

尝试使用简单的cmd脚本导致此输出:

    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.

有没有办法让这个工作正常?我想它应该能够传递驱动器号或让浏览器使用棒作为工作目录,但我不知道如何。由于我想在旅途中使用棒,我宁愿避免硬编码我当地的驱动器号。

2 个解决方案

#1


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

我认为最简单的解决方案是创建一个批处理文件来为您执行此操作。像这样名为activatekey.cmd的东西:

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:

将文件activatekey.cmd放入USB记忆棒中,并将autorun.inf更改为:

[AutoRun]
shell\pageant=Activate SSH Key
shell\pageant\command=activatekey.cmd

#2


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

它似乎是“Path”系统变量。 :(您可以将驱动器添加到路径,但获取驱动器号是问题。:-(

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

更新1:您可以使用VB脚本获取驱动器号。

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

更新2:是的,我认为你可以做到这一点。查看此页面。

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

更新3:我测试了脚本。它很棒。

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.

使用一些文件存在检查方法来区分多个USB驱动器。

#1


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

我认为最简单的解决方案是创建一个批处理文件来为您执行此操作。像这样名为activatekey.cmd的东西:

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:

将文件activatekey.cmd放入USB记忆棒中,并将autorun.inf更改为:

[AutoRun]
shell\pageant=Activate SSH Key
shell\pageant\command=activatekey.cmd

#2


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

它似乎是“Path”系统变量。 :(您可以将驱动器添加到路径,但获取驱动器号是问题。:-(

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

更新1:您可以使用VB脚本获取驱动器号。

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

更新2:是的,我认为你可以做到这一点。查看此页面。

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

更新3:我测试了脚本。它很棒。

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.

使用一些文件存在检查方法来区分多个USB驱动器。