$shortcutFolder = "C:\ShortcutFolder" # Specify the folder containing the shortcuts
# Loop through shortcuts to create registry keys
foreach ($shortcut in Get-ChildItem -Path $shortcutFolder -Filter "*.lnk") {
$shortcutName = $shortcut.BaseName
# Get the target path and icon location of the shortcut
$shell = New-Object -ComObject WScript.Shell
$shortcutObject = $shell.CreateShortcut($shortcut.FullName)
$shortcutPath = $shortcutObject.TargetPath
$shortcutIcon = $shortcutObject.IconLocation
$publisher = "Uninstall removes registry. Program is untouched."
# Check if the shortcut specifies an icon
if ($shortcutIcon -ne ",0") {
# Attempt to use the icon specified in the shortcut
$icon = $shortcutIcon
} else {
# Fall back to extracting icon from the executable file
$icon = $shortcutPath
}
# Create registry key for the shortcut under WOW6432Node
$keyPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$shortcutName"
if (-not (Test-Path $keyPath)) {
# If the registry key doesn't exist, create it
New-Item -Path $keyPath -Force
# Set DisplayName value to the shortcut name
Set-ItemProperty -Path $keyPath -Name "DisplayName" -Value $shortcutName
# Set publisher value
Set-ItemProperty -Path $keyPath -Name "Publisher" -Value $publisher
# Set UninstallString value to execute uninstallation logic directly
$uninstallCommand = "REG DELETE `"HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$shortcutName`" /f"
$uninstallString = "cmd.exe /c $uninstallCommand"
Set-ItemProperty -Path $keyPath -Name "UninstallString" -Value $uninstallString
# Set DisplayIcon value to the icon extracted from the shortcut or executable
Set-ItemProperty -Path $keyPath -Name "DisplayIcon" -Value $icon
}
}