Powershell,UPnP设备的快捷方式

时间:2017-01-27 11:47:42

标签: windows powershell upnp

我正在尝试创建PowerShell脚本,以创建UPnP设备的桌面快捷方式。我已成功使用$ WScriptShell.CreateShortcut()创建.exe文件或http地址的快捷方式,但我不明白如何指定设备的地址。但是,我可以通过右键单击Windows资源管理器中的设备手动创建快捷方式,但如何以编程方式执行相同操作?

1 个答案:

答案 0 :(得分:0)

使用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