-
Notifications
You must be signed in to change notification settings - Fork 0
/
move-to-start.ps1
52 lines (47 loc) · 1.79 KB
/
move-to-start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
param(
$path = $pwd
)
function IsAdministrator
{
$Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
$Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
}
function IsUacEnabled
{
(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System).EnableLua -ne 0
}
#
# Main script
#
$currentPath = $pwd
if (!(IsAdministrator))
{
if (IsUacEnabled)
{
[string[]]$argList = @('-NoProfile', '-NoExit', '-File', $MyInvocation.MyCommand.Path)
$argList += $MyInvocation.BoundParameters.GetEnumerator() | Foreach {"-$($_.Key)", "$($_.Value)"}
$argList += $MyInvocation.UnboundArguments
$argList += "-path $pwd"
Start-Process PowerShell.exe -Verb Runas -ArgumentList $argList
return
}
else
{
throw "You must be administrator to run this script"
}
}
Write-Output "Path: $path"
Write-Output "Current directory: $pwd"
Write-Output "Compiling."
C:\Program` Files\AutoHotkey\Compiler\Ahk2Exe.exe /in "$path\Keyboardy.ahk" /out "$path\Keyboardy.exe"
Write-Output "Finished compiling."
# Create a scheduled task to run Keyboardy on login or startup
$Action = New-ScheduledTaskAction -Execute "$path\Keyboardy.exe"
$Trigger = New-ScheduledTaskTrigger -AtLogOn
$Settings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel
$Principal = New-ScheduledTaskPrincipal -RunLevel Highest -LogonType Interactive -UserId 'Abdulrhman'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal
#Unregister-ScheduledTask -TaskName 'Keyboardy startup'
Register-ScheduledTask -TaskName 'Keyboardy startup' -InputObject $Task
Read-Host -Prompt "Press Enter to exit"