我已经为 USB 驱动器分配了一个名称,我想知道是否有一种简单的方法可以让桌面快捷方式基于名称而不是字母来定位它。
所以代替: F:\program_to_run.exe 它会像: DRIVENAME:\program_to_run.exe
虽然上述显然行不通,但可以使用快捷方式或简单的批处理文件完成类似的操作吗?
我已经为 USB 驱动器分配了一个名称,我想知道是否有一种简单的方法可以让桌面快捷方式基于名称而不是字母来定位它。
所以代替: F:\program_to_run.exe 它会像: DRIVENAME:\program_to_run.exe
虽然上述显然行不通,但可以使用快捷方式或简单的批处理文件完成类似的操作吗?
既然您刚刚进入 VB.Net,那么创建一个命令行程序来为您做这件事怎么样?
粘贴此代码:
Module Module1
Sub Main()
Dim program = ""
Dim drive As String = ""
Try
'Get the commandLine, without thhis application name or the beginning space
Dim commandLine As String = Environment.CommandLine.Replace(System.Reflection.Assembly.GetExecutingAssembly().Location, "").Replace("""", "").Substring(1)
'Get the DriveNAme part of the commaneLine
Dim driveName As String = commandLine.Split(":"c)(0)
drive = GetDriveByName(driveName)
'Get the Program Name part of the commandLine
program = commandLine.Split(":"c)(1)
If drive.Length = 0 Then Throw New Exception("No drive was found with the name '" + driveName + "'")
Dim starter As New System.Diagnostics.ProcessStartInfo(drive + program)
starter.UseShellExecute = True
System.Diagnostics.Process.Start(starter)
Catch ex As Exception
Console.WriteLine("Failed starting " + drive + program + ". " + ex.Message)
End Try
End Sub
''' <summary>Returns the drive letter of the Fixed or Removable drive with the specified name</summary>
''' <param name="DriveName"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetDriveByName(ByVal DriveName As String) As String
Dim returnDrive As String = ""
For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()
If (drive.DriveType = (IO.DriveType.Fixed Or IO.DriveType.Removable)) Then 'Only interested in removable drives
If (drive.VolumeLabel.Equals(DriveName, StringComparison.OrdinalIgnoreCase)) Then
'This is our drive!
returnDrive = drive.Name
End If
End If
Next drive
Return returnDrive
End Function
End Module
然后 build 给你的应用程序起一个好听的名字(例如 StartByDriveName.exe)并编译它。
您现在可以在批处理文件中使用它:
StartByDriveName <driveName>:<path>\ProgramName
例如 StartByDriveName MomsUSB:\Program Files\Excel.Exe
我相信您可以在磁盘管理实用程序中为各个设备永久分配某个驱动器号