Enhance autostart setup with a one-command installer and improve script logic for KVM switch launch
This commit is contained in:
@@ -56,22 +56,24 @@ uv run monitorcontrol_main.py
|
||||
|
||||
## Autostart
|
||||
|
||||
### Easiest option: Startup folder
|
||||
### Recommended: one-command installer
|
||||
|
||||
From the project folder, run:
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File .\install_autostart.ps1
|
||||
```
|
||||
|
||||
This creates or updates a Startup shortcut for the current Windows user and points it to this folder's `start_kvm_switch_background.vbs`.
|
||||
No hardcoded `C:\Users\...` path is required, so it works across tower/laptop deployments.
|
||||
|
||||
### Manual option: Startup folder
|
||||
|
||||
1. Press `Win + R`
|
||||
2. Run:
|
||||
2. Run `shell:startup`
|
||||
3. Create a shortcut to this repo's `start_kvm_switch_background.vbs`
|
||||
|
||||
```text
|
||||
shell:startup
|
||||
```
|
||||
|
||||
3. Create a shortcut in that folder pointing to:
|
||||
|
||||
```text
|
||||
C:\Users\LagoWorkStation\OneDrive\Documentos\BE-terna\Internal - KVM Switch\start_kvm_switch_background.vbs
|
||||
```
|
||||
|
||||
This starts the app at logon in the background (no persistent console window).
|
||||
The launcher resolves its own folder dynamically, so the project can live in different user directories.
|
||||
|
||||
### Cleaner option: Task Scheduler
|
||||
|
||||
@@ -86,7 +88,7 @@ wscript.exe
|
||||
Arguments:
|
||||
|
||||
```text
|
||||
"C:\Users\LagoWorkStation\OneDrive\Documentos\BE-terna\Internal - KVM Switch\start_kvm_switch_background.vbs"
|
||||
"<full-path-to-project>\\start_kvm_switch_background.vbs"
|
||||
```
|
||||
|
||||
Set the trigger to `At log on`. Optional: enable `Hidden` in task settings.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
param(
|
||||
[string]$ShortcutName = "Internal KVM Switch.lnk"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$launcher = Join-Path $scriptDir "start_kvm_switch_background.vbs"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $launcher)) {
|
||||
throw "Launcher not found: $launcher"
|
||||
}
|
||||
|
||||
$startupFolder = [Environment]::GetFolderPath("Startup")
|
||||
$shortcutPath = Join-Path $startupFolder $ShortcutName
|
||||
|
||||
$wscript = New-Object -ComObject WScript.Shell
|
||||
$shortcut = $wscript.CreateShortcut($shortcutPath)
|
||||
$shortcut.TargetPath = "$env:WINDIR\System32\wscript.exe"
|
||||
$shortcut.Arguments = """$launcher"""
|
||||
$shortcut.WorkingDirectory = $scriptDir
|
||||
$shortcut.IconLocation = "$env:WINDIR\System32\shell32.dll,220"
|
||||
$shortcut.Save()
|
||||
|
||||
Write-Host "Autostart shortcut created/updated:"
|
||||
Write-Host " $shortcutPath"
|
||||
Write-Host "Target launcher:"
|
||||
Write-Host " $launcher"
|
||||
@@ -1,3 +1,23 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0"
|
||||
|
||||
where uv >nul 2>&1
|
||||
if %errorlevel%==0 (
|
||||
uv run kvm-switch
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
if exist ".venv\Scripts\kvm-switch.exe" (
|
||||
call ".venv\Scripts\kvm-switch.exe"
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
if exist ".venv\Scripts\python.exe" (
|
||||
call ".venv\Scripts\python.exe" -m main
|
||||
exit /b %errorlevel%
|
||||
)
|
||||
|
||||
echo [ERROR] Could not start KVM Switch.
|
||||
echo [ERROR] Neither "uv" nor ".venv" runtime was found.
|
||||
exit /b 1
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
Option Explicit
|
||||
|
||||
Dim shell
|
||||
Dim fso
|
||||
Dim projectPath
|
||||
Dim launcherPath
|
||||
Dim command
|
||||
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
projectPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
|
||||
command = "cmd.exe /c cd /d """ & projectPath & """ && uv run kvm-switch"
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
projectPath = fso.GetParentFolderName(WScript.ScriptFullName)
|
||||
launcherPath = fso.BuildPath(projectPath, "start_kvm_switch.cmd")
|
||||
command = "cmd.exe /c """ & launcherPath & """"
|
||||
|
||||
' Run hidden and do not wait.
|
||||
shell.Run command, 0, False
|
||||
|
||||
Reference in New Issue
Block a user