Skip to content

Commit

Permalink
chore: add guide for run-as-admin-at-logon
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Apr 16, 2024
1 parent da5f6bd commit 195ef9b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Tips: **Hold `Alt` and strike `Backtick/Tab` to cycle through, press `Alt + Back
## Install

Download `windows-switcher.zip` from the [Github Release](https://github.com/sigoden/windows-switcher/releases), extract `window-switcher.exe`, run it.

> window-switcher.exe is a portable single-file program (less than 500 KB in size). No installation is required.

Expand Down Expand Up @@ -54,6 +55,36 @@ hotkey = alt+tab
ignore_minimal = no
```

## Running as Administrator at Logon

Running `window-switcher.exe` with standard permissions limits its functionality, especially when interacting with system apps like Task Manager that require admin rights. Elevating its privileges enables seamless interaction with all applications.

You can easily accomplish this using Task Scheduler. Just follow these steps:

1. **Open Task Scheduler**: You can do this by searching for "Task Scheduler" in the Start menu.
2. **Create a New Task**: In the Task Scheduler, navigate to "Action" > "Create Task..."
3. **Configure General Tab**:
- Give your task a name (e.g. WindowSwitcher)
- Check "Run only when user is logged on".
- Check "Run with highest privileges".
4. **Configure Triggers Tab**:
- Click "New..."
- For "Begin the task", choose "At logo on"
- For "Settings", check "Special User"
5. **Configure Actions Tab**:
- Click "New...".
- For "Action", choose "Start a program".
- Browse and select the program you want to start or input the path manually.
6. **OK/Save**: Once you've configured your task, click "OK" to save it. You might be prompted to enter an admin password.

For your convenience, we've provided a PowerShell script that automates the process.

Run the following script in an administrator PowerShell window:

```ps1
.\run-as-admin-at-logon.ps1 <path-to-window-switcher.exe>
```

## License

Copyright (c) 2023-2024 window-switcher developers.
Expand Down
35 changes: 35 additions & 0 deletions run-as-admin-at-logon.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Create a scheduled task that ensures `window-switcher.exe` runs with the admin privileges at logon

$programPath = $args[0]

if (-not $programPath) {
$programPath = Read-Host "Enter the full path to window-switcher.exe"
} else {
$programPath = (Resolve-Path $programPath).Path
}

# Check if the file exists at the provided path
if (-not (Test-Path $programPath)) {
Write-Host "Invalid path at '$programPath'"
exit 1
}

# Task name
$taskName = "WindowSwitcher"

# Current User
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$userId = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value

# Create a Scheduled Task Action
$action = New-ScheduledTaskAction -Execute $programPath

# Create a Scheduled Task Trigger
$trigger = New-ScheduledTaskTrigger -AtLogon -User $user

# Set to run with highest privileges
$principal = New-ScheduledTaskPrincipal -UserId $userId -LogonType Interactive -RunLevel Highest

# Register the task
Register-ScheduledTask -TaskName $taskName -Action $action -TaskPath "\" `
-Principal $principal -Trigger $trigger -Description "Run window-switcher.exe at logon" -Force

0 comments on commit 195ef9b

Please sign in to comment.