windows 从命令提示符更改快捷方式的目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/416957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change a shortcut's target from command prompt
提问by Mark A. Nicolosi
I'm normally a Linux guy, but I need to write a batch script on Windows to change the target of some shortcuts. Is there a command to do that?
我通常是一个 Linux 人,但我需要在 Windows 上编写一个批处理脚本来更改某些快捷方式的目标。有命令可以这样做吗?
回答by Tmdean
I doubt there is a way to do it with a batch script. It's doablein VBScript, though.
我怀疑有没有办法用批处理脚本来做到这一点。不过,它在 VBScript 中是可行的。
Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Wherever\Shortcut.lnk")
shortcut.TargetPath = "C:\Wherever\Whatever.txt"
shortcut.Save
Save the script in a file ending in vbs and run it from the command line using cscript whatever.vbs
.
将脚本保存在以 vbs 结尾的文件中,并使用cscript whatever.vbs
.
(Don't be fooled by the name -- CreateShortcut
is used to both create and modify shortcuts.)
(不要被名称所迷惑——CreateShortcut
用于创建和修改快捷方式。)
回答by Mark A. Nicolosi
There isn't a native program that comes with windows to achieve this. I scoured the internet for this same functionality awhile ago and stumbled upon the free software XXMKLINK.
没有 Windows 附带的本机程序来实现这一点。不久前,我在互联网上搜索了相同的功能,并偶然发现了免费软件XXMKLINK。
With XXMKLINK, you can write a batch file for software installation which has been done by specialized instllation programs. Basically, XXMKLINK is to gather the information from a command line and package it into a shortcut.
Command syntax of XXMKLINK:
xxmklink spath opath [ arg [ wdir [ desc [ mode [ icon[:n] ]]]]] where spath path of the shortcut (.lnk added as needed) opath path of the object represented by the shortcut arg argument string (use quotes with space, see below) wdir path of the working directory (for "Start in") desc description string (shown in Shosrtcut's Properties) mode display mode (1:Normal [default], 3:Maximized, 7:Minimized) icon[:n] icon file [with optional icon index value n] In addition to the above, the following switches are supported which can be placed in any position in the command line. /p prompts before action /q no output when successful (quiet) /e checks error condition strictly
使用 XXMKLINK,您可以编写用于软件安装的批处理文件,该文件由专门的安装程序完成。基本上,XXMKLINK就是从命令行收集信息,打包成快捷方式。
XXMKLINK 命令语法:
xxmklink spath opath [ arg [ wdir [ desc [ mode [ icon[:n] ]]]]] where spath path of the shortcut (.lnk added as needed) opath path of the object represented by the shortcut arg argument string (use quotes with space, see below) wdir path of the working directory (for "Start in") desc description string (shown in Shosrtcut's Properties) mode display mode (1:Normal [default], 3:Maximized, 7:Minimized) icon[:n] icon file [with optional icon index value n] In addition to the above, the following switches are supported which can be placed in any position in the command line. /p prompts before action /q no output when successful (quiet) /e checks error condition strictly
The downside is you'll need to copy the xxmklink exe onto each computer with the batch script.
缺点是您需要使用批处理脚本将 xxmklink exe 复制到每台计算机上。
A link to download it is available at the bottom of the linked page.
链接页面底部提供下载链接。