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 -

clear
$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"
$slink.Save() 


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..

Enjoy!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...