[UPDATE 2008-05-13] Updated this post to use syntax Powershell 1.0 syntax instead of the original Monad syntax.
A simple example that shows you how to create Start Menu shortcut.
This example illustrates how to
Things to notice
Powershell Example
#------------------------------------- $shortcut_group_name = "My Start Menu Shortcuts"$shortcut_name = "Visit Microsoft's website"$shortcut_target = "http://www.microsoft.com"
$sh = new-object -com "WScript.Shell" $p = $sh.SpecialFolders.item("AllUsersPrograms")if ( -not ( test-path $p ) ){ throw "Folder does not exist"}$p= join-path $p $shortcut_group_nameif ( -not ( test-path $p ) ){ new-item $p -type directory}
$lnk = $sh.CreateShortcut( (join-path $p $shortcut_name) + ".lnk" ) $lnk.TargetPath = $shortcut_target$lnk.Save()
#-------------------------------------
Python Example
#------------------------------------- import os import sys import win32com.client shortcut_group_name = "My Start Menu Shortcuts" shortcut_name = "Visit Microsoft's website" shortcut_target = "http://www.microsoft.com" sh = win32com.client.Dispatch( "WScript.Shell" ) p = sh.SpecialFolders("AllUsersPrograms") assert( os.path.isdir(p) ) p= os.path.join( p, shortcut_group_name) if ( not os.path.isdir(p) ) : os.makedirs(p) lnk = sh.CreateShortcut( os.path.join( p, shortcut_name + ".lnk" )) lnk.TargetPath = shortcut_target lnk.Save() #-------------------------------------