【发布时间】:2017-01-27 11:47:41
【问题描述】:
我正在尝试创建用于创建 UPnP 设备的桌面快捷方式的 powershell 脚本。我已成功使用 $WScriptShell.CreateShortcut() 创建 .exe 文件或 http 地址的快捷方式,但我不明白如何指定设备的地址。但是,我可以通过右键单击 Windows 资源管理器中的设备来手动创建快捷方式,但我如何以编程方式执行相同操作?
【问题讨论】:
标签: windows powershell upnp
我正在尝试创建用于创建 UPnP 设备的桌面快捷方式的 powershell 脚本。我已成功使用 $WScriptShell.CreateShortcut() 创建 .exe 文件或 http 地址的快捷方式,但我不明白如何指定设备的地址。但是,我可以通过右键单击 Windows 资源管理器中的设备来手动创建快捷方式,但我如何以编程方式执行相同操作?
【问题讨论】:
标签: windows powershell upnp
使用 PS 创建自定义快捷方式:
# Quick shortcut creation script
# This if the variable that will hold the computer name of your target device
$computer = "The Computer Name"
# This command will create the shortcut object
$WshShell = New-Object -ComObject WScript.Shell
# This is where the shortcut will be created
$Shortcut = $WshShell.CreateShortcut("\\$computer\C$\Users\Public\Desktop\SuperAwesomeness.lnk")
# This is the program the shortcut will open
$Shortcut.TargetPath = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
# This is the icon location that the shortcut will use
$Shortcut.IconLocation = "C:\AwesomeIcon.ico,0"
# This is any extra parameters that the shortcut may have. For example, opening to a google.com when internet explorer opens
$Shortcut.Arguments = "google.com"
# This command will save all the modifications to the newly created shortcut.
$Shortcut.Save()
替代示例用于移除 USB:
$AppLocation = "C:\Windows\System32\rundll32.exe"
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\USB Hardware.lnk")
$Shortcut.TargetPath = $AppLocation
$Shortcut.Arguments ="shell32.dll,Control_RunDLL hotplug.dll"
$Shortcut.IconLocation = "hotplug.dll,0"
$Shortcut.Description ="Device Removal"
$Shortcut.WorkingDirectory ="C:\Windows\System32"
$Shortcut.Save()
这里是参考链接:Custom Shortcut with PS
【讨论】: