-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add guide for run-as-admin-at-logon
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |