从命令行创建快捷方式

从命令行创建快捷方式

在 Windows XP 中有没有办法从命令行创建文件的快捷方式?

如果没有,创建文件快捷方式的最简单的 Winapi 调用是什么?

答案1

答案2

您可以使用实用程序 NirCmd http://www.nirsoft.net/utils/nircmd.html

例子

nircmd.exe shortcut "C\Windows:\System32\calc.exe"    "C:\Calculators" "Windows Calculator" 

答案3

我为此制作了 ShortcutMaker.vbs:

Sub Shortcut(Application,Name,Location,Icon,Hotkey)
  Dim objShell,DesktopPath,objShortCut,MyTab
  If IsEmpty(Icon) Then 
    Icon = "winver.exe,0"
  End If
  If IsEmpty(Hotkey) Then 
     NoHotkey = True
  End If
  Set objShell = CreateObject("WScript.Shell")
  MyTab = Split(Application,"\")
  If Name = "" Then
    Name = MyTab(UBound(MyTab))
  End if
  Set objShortCut = objShell.CreateShortcut(DblQuote(Location & "\" & Name & ".lnk"))
  With objShortCut
    .TargetPath = DblQuote(Application)
    .IconLocation = Icon
    If Not(NoHotkey) Then
       .Hotkey = Hotkey
    End If
    .Save
  End With
End Sub
Sub DblQuote(Str)
  DblQuote = Chr(34) & Str & Chr(34)
End Sub

然后您可以像这样调用 Shortcut():

Call Shortcut(Application,Name,LocationFolder,OptionalIcon,OptionalHotkey)

相关内容