Create Shortut

From psadt | Evergreen Application Management
Jump to navigation Jump to search

About

Powershell.png

Powershell function to create a shortcut in the Start Menu.


Function

#region Function
Function CreateShortcut
    {
	Param (
		[string]$Path,
		[string]$TargetPath,
		[string]$WorkingDirectory,
		[string]$Arguments,
		[string]$IconLocation,
		[string]$Description
		)
	[__comobject]$Shell = New-Object -ComObject 'WScript.Shell' -ErrorAction 'Stop'
	$shortcut = $shell.CreateShortcut($Path)
	$shortcut.TargetPath = $targetPath
	$shortcut.WorkingDirectory = $workingDirectory
	$shortcut.Arguments = $arguments
	$shortcut.IconLocation = $IconLocation
	$shortcut.Description = $description
	$shortcut.Save()
    }

#endregion


Example usage

[string]$envStartMenu = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs"

[string]$appPath = "$env:ProgramFiles\Oracle\sqldeveloper"

CreateShortcut -Path "$envStartMenu\Oracle SQL Developer.lnk" -TargetPath "$appPath\sqldeveloper.exe" -WorkingDirectory $appPath -IconLocation "$appPath\sqldeveloper.exe" -Description "Oracle SQL Developer"