从批处理文件为 exe 创建快捷方式 [英] creating a shortcut for a exe from a batch file

查看:44
本文介绍了从批处理文件为 exe 创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为批处理文件中的 exe 创建快捷方式.

how to create a shortcut for a exe from a batch file.

我试过了

call link.bat "c:program FilesApp1program1.exe" "C:Documents and Settings\%USERNAME%Desktop" "C:Documents and Settings\%USERNAME%Start MenuPrograms" "Program1 shortcut"

但是没有用.

link.bat 可以在http://www.robvanderwoude.com/amb_shortcuts.html

link.bat can be found at http://www.robvanderwoude.com/amb_shortcuts.html

推荐答案

您的链接指向 Windows 95/98 版本,我猜您至少有 Windows 2000 或 XP.您应该在此处尝试使用 NT 版本.

Your link points to a Windows 95/98 version and I guess you have at least Windows 2000 or XP. You should try the NT version here.

或者使用一些可以从命令行调用的 VBScript:

Alternatively use a little VBScript that you can call from the command line:

set objWSHShell = CreateObject("WScript.Shell")
set objFso = CreateObject("Scripting.FileSystemObject")

' command line arguments
' TODO: error checking
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)

set objSC = objWSHShell.CreateShortcut(sShortcut) 

objSC.TargetPath = sTargetPath
objSC.WorkingDirectory = sWorkingDirectory

objSC.Save

将文件另存为 createLink.vbs 并像这样调用它以获得您最初尝试的内容:

Save the file as createLink.vbs and call it like this to get what you originally tried:

cscript createLink.vbs "C:Documents and Settings\%USERNAME%DesktopProgram1 shortcut.lnk" "c:program FilesApp1program1.exe" 
cscript createLink.vbs "C:Documents and Settings\%USERNAME%Start MenuProgramsProgram1 shortcut.lnk" "c:program FilesApp1program1.exe" 

也就是说,我敦促您不要使用像开始菜单"这样的硬编码路径,因为它们在 Windows 的本地化版本中是不同的.修改脚本以使用特殊文件夹.

That said I urge you not to use hardcoded paths like "Start Menu" since they're different in localized versions of windows. Modify the script instead to use special folders.

这篇关于从批处理文件为 exe 创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆