在任何 Windows 计算机上自动创建快捷方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3673250/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:13:31  来源:igfitidea点击:

Automatically creating shortcuts on any Windows computer

windowsshortcut

提问by Erin McKay

I'd like to create some sort of script that will create a particular shortcut on the desktop of any Windows computer. The idea is to make the script available (to students in a course) so that they can download it to their computer and run it just by clicking it (i.e. not running it at the command-line). The script will have to check for some particular folders and files, and, if they exist, create the shortcut.

我想创建某种脚本,可以在任何 Windows 计算机的桌面上创建特定的快捷方式。这个想法是使脚本可用(对课程中的学生),以便他们可以将它下载到他们的计算机并通过单击它来运行它(即不在命令行运行它)。该脚本必须检查某些特定的文件夹和文件,如果存在,则创建快捷方式。

I'm a Linux guy and know very little about Windows, and so I am not even sure where to start to looking. I considered into using a Python script to do this, but that apparently requires installing some Windows-specific extensions, which I don't want to insist that that users do.

我是一个 Linux 人,对 Windows 知之甚少,所以我什至不知道从哪里开始寻找。我考虑过使用 Python 脚本来执行此操作,但这显然需要安装一些特定于 Windows 的扩展,我不想坚持让用户这样做。

回答by RBerteig

This can be done in VBScript, using the Windows Script Hostwhich should be installed and usable on nearly any recent enough copy of Windows.

这可以在 VBScript 中完成,使用Windows Script Host,它应该安装在几乎所有足够近的 Windows 副本上并可用。

You want the CreateShortcut()method of the WshShell objectwhich gets you an object representing a shortcut. You'd modify its properties and use its Save()method to actually create the shortcut file.

您需要WshShell 对象CreateShortcut()方法,该方法为您提供一个表示快捷方式的对象。您将修改其属性并使用其方法来实际创建快捷方式文件。Save()

I've linked to the scripting guide at MSTN, as well as a page specific to the shell object. That should be a good starting point.

我已经链接到 MSTN 的脚本指南,以及特定于 shell 对象的页面。这应该是一个很好的起点。

回答by Brad

For this, I often work up a quick NSIS script and compile it to an EXE. The result is a very small executable. You can download NSIS itself at http://nsis.sourceforge.net/Download. I recommend HM NIS Editto start with, as it has a wizard that builds a base script for you. Most of that wizard won't be applicable to your situation, but it is a good way to get started. Notepad++also does syntax highlighting for NSIS.

为此,我经常编写一个快速的 NSIS 脚本并将其编译为 EXE。结果是一个非常小的可执行文件。您可以在http://nsis.sourceforge.net/Download下载 NSIS 本身。我建议从HM NIS Edit开始,因为它有一个向导可以为您构建基本脚本。该向导的大部分内容不适用于您的情况,但这是一个很好的入门方法。 Notepad++还为 NSIS 进行语法高亮显示。