-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManage-WindowFollower.ps1
More file actions
41 lines (39 loc) · 1.4 KB
/
Copy pathManage-WindowFollower.ps1
File metadata and controls
41 lines (39 loc) · 1.4 KB
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
param(
[Parameter(Mandatory = $true)]
[ValidateSet("Install", "Start", "Stop", "Disable")]
[string]$Action
)
$BaseDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$TaskName = "WindowFollower"
$CorePath = Join-Path $BaseDir "WindowFollower.ps1"
function Start-Direct {
$command = 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "' + $CorePath + '" -Mode Move -BaseDir "' + $BaseDir + '"'
$shell = New-Object -ComObject WScript.Shell
[void]$shell.Run($command, 0, $false)
}
switch ($Action) {
"Install" {
$taskRun = 'powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + $CorePath + '" -Mode Move -BaseDir "' + $BaseDir + '"'
schtasks.exe /Create /TN $TaskName /SC ONLOGON /TR $taskRun /RL HIGHEST /F
if ($LASTEXITCODE -ne 0) { exit 1 }
schtasks.exe /Run /TN $TaskName | Out-Null
if ($LASTEXITCODE -ne 0) { exit 1 }
}
"Start" {
schtasks.exe /Query /TN $TaskName 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) { schtasks.exe /Run /TN $TaskName | Out-Null }
else { Start-Direct }
}
"Stop" {
try {
$stopEvent = [System.Threading.EventWaitHandle]::OpenExisting("Global\WindowFollowerStop")
[void]$stopEvent.Set()
$stopEvent.Dispose()
Start-Sleep -Milliseconds 500
} catch { }
schtasks.exe /End /TN $TaskName 2>$null | Out-Null
}
"Disable" {
schtasks.exe /Delete /TN $TaskName /F 2>$null | Out-Null
}
}