[CmdletBinding(SupportsShouldProcess = $true)] param( [switch]$Remove, [switch]$AllUsers ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" $scriptDir = Split-Path -Parent $PSCommandPath $vbsLauncher = Join-Path $scriptDir "start_screenjob_tray_hidden.vbs" $shortcutName = "ScreenJob Tray.lnk" if (-not (Test-Path -LiteralPath $vbsLauncher)) { throw "Launcher file not found: $vbsLauncher" } $startupFolder = if ($AllUsers) { [Environment]::GetFolderPath("CommonStartup") } else { [Environment]::GetFolderPath("Startup") } $shortcutPath = Join-Path $startupFolder $shortcutName if ($Remove) { if (Test-Path -LiteralPath $shortcutPath) { if ($PSCmdlet.ShouldProcess($shortcutPath, "Remove startup shortcut")) { Remove-Item -LiteralPath $shortcutPath -Force Write-Host "Removed startup shortcut: $shortcutPath" } } else { Write-Host "No startup shortcut found at: $shortcutPath" } return } if ($PSCmdlet.ShouldProcess($shortcutPath, "Create startup shortcut")) { $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut($shortcutPath) $shortcut.TargetPath = "$env:SystemRoot\System32\wscript.exe" $shortcut.Arguments = '"' + $vbsLauncher + '"' $shortcut.WorkingDirectory = $scriptDir $shortcut.Description = "Launch ScreenJob tray icon at sign-in." $shortcut.Save() Write-Host "Created startup shortcut: $shortcutPath" }