mirror of
https://github.com/peter-tanner/numlock-indicator.git
synced 2024-11-30 06:10:22 +08:00
18 lines
947 B
PowerShell
18 lines
947 B
PowerShell
$TaskName = "numlock-indicator"
|
|
$ScriptPath = Join-Path $PSScriptRoot "start.ps1"
|
|
$Action = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe' -Argument "-WindowStyle Hidden -File `"$ScriptPath`""
|
|
$Trigger = New-ScheduledTaskTrigger -AtLogon
|
|
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
|
|
|
if (!$(Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue)) {
|
|
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Settings $Settings -User $env:USERNAME
|
|
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
|
|
Start-ScheduledTask -TaskName $TaskName
|
|
Write-Output "Task '$TaskName' created successfully."
|
|
} else {
|
|
Write-Output "Failed task creation. Run this script in admin mode."
|
|
}
|
|
} else {
|
|
Write-Output "Task '$TaskName' already exists."
|
|
}
|