操作系统:Windows7
我正在尝试通过批处理创建指向桌面文件夹的链接,如下所示:
mklink "%userprofile%\Desktop\MyExe" "%~dp0\MyExe.exe"
该命令有效,但如何指出MyExe.exe
在"%~dp0"
处执行?
MyExe.exe
看起来像在当前文件夹中运行,因此无法加载我的配置文件。
更新
通过使用VBS获得了不同的问题,在下面运行代码将创建一个快捷方式 对于C:\Users\jiu\Desktop\MyExe.exe
,但我想要MyExe.exe
。
Set oWS = WScript.CreateObject("WScript.Shell")
userProfilePath = oWS.ExpandEnvironmentStrings("%UserProfile%")
currParentFolder = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
linkPath = userProfilePath + "\Desktop\MyExe.LNK"
Set oLink = oWS.CreateShortcut(linkPath)
oLink.TargetPath = "MyExe.exe"
oLink.WorkingDirectory = currParentFolder
oLink.Save
答案 0 :(得分:1)
根据您提供的信息,这是一个奇怪的批处理文件,应该为您创建桌面快捷方式:
;@Rundll32 AdvPack.dll,LaunchINFSection "%~0",,1
;@GoTo :EOF
[Version]
Signature="$Windows NT$"
[DefaultInstall]
ProfileItems=AddLnk
[AddLnk]
Name="MyExe",8,16
CmdLine=1,,"MyExe.exe"
InfoTip="Execute MyExe.exe"
WorkingDir=1
您可以选择修改:
8
行上双引号内的字符串来显示名称。 9
行上双引号内的字符串。 10
上双引号内的字符串。 答案 1 :(得分:0)
mklink
不会创建*.lnk
快捷方式,而是symbolic/hard link,它只是物理文件的新名称。由于链接在桌面上,如果双击文件
您必须创建shortcut。一种方法是使用下面的vbs脚本
Set oWS = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
sLinkFile = strDesktop & "\MyExe.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = WScript.Arguments(0) & "\" & WScript.Arguments(1)
' oLink.Arguments = ""
' oLink.Description = "MyExe"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = WScript.Arguments(0) & "\" & WScript.Arguments(1) & ", 2"
' oLink.WindowStyle = "1"
oLink.WorkingDirectory = WScript.Arguments(0)
oLink.Save
将其另存为,然后调用
cscript "%~dp0" "MyExe.exe"
您也可以从powershell or various other tools
创建它$objShell = New-Object -ComObject WScript.Shell
$lnk = $objShell.CreateShortcut("$home\Desktop\MyExe.lnk")
$lnk.TargetPath = ".\MyExe.exe"
$lnk.Save()
答案 2 :(得分:0)
我发现:
Set oWS = WScript.CreateObject("WScript.Shell")
userProfilePath = oWS.ExpandEnvironmentStrings("%UserProfile%")
currParentFolder = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
linkPath = userProfilePath + "\Desktop\MyExe.LNK"
targetPath = currParentFolder + "\MyExe.EXE"
Set oLink = oWS.CreateShortcut(linkPath)
oLink.TargetPath = targetPath
oLink.WorkingDirectory = currParentFolder
oLink.Save