Add Windows service host and system tray controller
All checks were successful
CI / test (push) Successful in 7s
All checks were successful
CI / test (push) Successful in 7s
This commit is contained in:
47
install_tray_startup_shortcut.ps1
Normal file
47
install_tray_startup_shortcut.ps1
Normal file
@@ -0,0 +1,47 @@
|
||||
[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"
|
||||
}
|
||||
Reference in New Issue
Block a user