This is the kind of thing that PowerShell is really good at, and is therefore a reason to eschew batch files and get on PowerShell the bandwagon.
PowerShell can talk to .NET. For example, you can get the location of the Desktop like this:
[Environment]::GetFolderPath("Desktop")
PowerShell can talk to COM objects, including WScript.Shell
, which can create shortcuts:
New-Object -ComObject WScript.Shell).CreateShortcut( ... )
So your script might look like:
$linkPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "MyShortcut.lnk"
$targetPath = Join-Path ([Environment]::GetFolderPath("ProgramFiles")) "MyCompany\MyProgram.exe"
$link = (New-Object -ComObject WScript.Shell).CreateShortcut( $linkpath )
$link.TargetPath = $targetPath
$link.Save()
Shortcuts have a lot of settings that WScript.Shell can't manipulate, like the "run as administrator" option. These are only accessible through the Win32 interface IShellLinkDataList
, which is a real pain to use, but it can be done.