Thursday, September 4, 2014

#25 : Create a ShortCut with Powershell

Creating a Shortcut might be a difficult task in any scripting language in Windows. Not sure how difficult or simple is there in Unix.

Let's take a look on the simple few lines which accomplish this task -

$wsc = New-Object -ComObject ("Wscript.Shell")$sc=Join-Path -Path "d:\test" -childpath "Notepad.lnk"
$slink=$wsc.CreateShortcut($sc)$slink.TargetPath = "C:\windows\notepad.exe"
$slink.WindowStyle = 0
$slink.Hotkey = "CTRL+SHIFT+F"
$slink.IconLocation = "notepad.exe, 0"
$slink.WorkingDirectory = "d:\Test"

Since this uses Wscript.Shell which is VBScript shell, there are some Windows version where you do not see desired output. Please let me know..


No comments:

Post a Comment