当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 创建快捷方式 .lnk 或 .url 文件

作者:精品下载站 日期:2024-12-14 08:14:16 浏览:12 分类:玩电脑

使用 PowerShell 创建快捷方式 .lnk 或 .url 文件


您是否曾经需要在编写脚本时创建快捷方式?快捷方式只是带有一些详细信息的 .lnk 文件,突出显示您要启动的文件的一些详细信息。许多人只是复制已经创建的快捷方式。借助 PowerShell,您实际上可以利用 New-Object commandlet 从头开始创建快捷方式。这是带有解释的快速总结。

步骤#1:第一步是创建一个引用 Wscript.Shell COM 对象的变量。

$Shell = New-Object -ComObject ("WScript.Shell")

步骤#2:第二步是定义快捷方式的位置和名称。以下示例将快捷方式添加到用户的桌面,名称为“您的快捷方式”。

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")

步骤#3:第三步是添加目标路径、任何相关参数以及可能需要的任何其他内容。

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")
$ShortCut.TargetPath="yourexecutable.exe"
$ShortCut.Arguments="-arguementsifrequired"
$ShortCut.WorkingDirectory = "c:\your\executable\folder\path";
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = "CTRL+SHIFT+F";
$ShortCut.IconLocation = "yourexecutable.exe, 0";
$ShortCut.Description = "Your Custom Shortcut Description";

步骤#4:最后一步是调用 Save() 方法来保存快捷方式。

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")
$ShortCut.TargetPath="yourexecutable.exe"
$ShortCut.Arguments="-arguementsifrequired"
$ShortCut.WorkingDirectory = "c:\your\executable\folder\path";
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = "CTRL+SHIFT+F";
$ShortCut.IconLocation = "yourexecutable.exe, 0";
$ShortCut.Description = "Your Custom Shortcut Description";
$ShortCut.Save()

步骤 #5:作为奖励,您可以在 Windows 中创建一个收藏夹,它是一个 .url 快捷方式。

$Shell = New-Object -ComObject ("WScript.Shell")
$Favorite = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.url")
$Favorite.TargetPath = "http://www.yoururl.com";
$Favorite.Save()

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯