I'm trying to create powershell script that creates a desktop shortcut to an UPnP device. 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. However, I can create a shortcut manually by right clicking the devices in Windows Explorer, but how do I do the same programmatically?
Creation of Custom Shortcut with 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:
$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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.