what is the windows script to add shortcuts to all users desktop?

thanks

Dani AI

Generated

If the goal is a desktop shortcut available to every account, there are three reliable approaches: let the installer create it, copy/create a .lnk under the system-wide desktop folder, or use an installer/OS API so you won’t rely on hard-coded paths.

A simple script approach is easiest for ad-hoc tasks. Use the Windows Script Host CreateShortcut method (VBScript) or the same COM object from PowerShell to create a .lnk in the common desktop folder. Resolve the common-desktop path through the OS API rather than hard-coding C:\Users\Public\Desktop (paths differ by OS and domain policies). Note that writing to the all-users desktop typically requires elevation when run from an installer or admin tool on Vista/7/8/10/11; installers should use the MSI CreateShortCut table so the product can remove the shortcut on uninstall and create advertised shortcuts when appropriate.

Example snippets (adjust target/icon/workdir and run elevated when required):

VBScript

Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
Set lnk = WshShell.CreateShortcut(strDesktop & "\MyApp.lnk")
lnk.TargetPath = "C:\Program Files\MyApp\myapp.exe"
lnk.IconLocation = "C:\Program Files\MyApp\myapp.exe,0"
lnk.WorkingDirectory = "C:\Program Files\MyApp"
lnk.Save

PowerShell

$desktop = [Environment]::GetFolderPath([Environment+SpecialFolder]::CommonDesktopDirectory)
$w = New-Object -ComObject WScript.Shell
$lnk = $w.CreateShortcut((Join-Path $desktop 'MyApp.lnk'))
$lnk.TargetPath = 'C:\Program Files\MyApp\myapp.exe'
$lnk.IconLocation = 'C:\Program Files\MyApp\myapp.exe,0'
$lnk.Save()

References: WSH CreateShortcut documentation, MSI CreateShortCut table, .NET/OS common-desktop folder and UAC overview for elevation requirements.

anyway i found it,
you can get that from the windows installer properties at run time when you run the installer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.