简体   繁体   English

Powershell,UPnP设备的快捷方式

[英]Powershell, shortcut to UPnP device

I'm trying to create powershell script that creates a desktop shortcut to an UPnP device. 我正在尝试创建Powershell脚本,该脚本创建到UPnP设备的桌面快捷方式。 I have successfully used $WScriptShell.CreateShortcut() to create a shortcut to an .exe file or a http address, but I don't understand how to specify the address of a device. 我已经成功地使用$ WScriptShell.CreateShortcut()创建了.exe文件或http地址的快捷方式,但是我不知道如何指定设备的地址。 However, I can create a shortcut manually by right clicking the devices in Windows Explorer, but how do I do the same programmatically? 但是,我可以通过右键单击Windows资源管理器中的设备来手动创建快捷方式,但是如何以编程方式执行同样的操作?

Creation of Custom Shortcut with PS: 使用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()

Alternate Example for removing USB: 删除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()

Here is the link for reference : Custom Shortcut with PS 这是参考链接: PS的自定义快捷方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM