-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.ps1
More file actions
75 lines (65 loc) · 3.06 KB
/
manager.ps1
File metadata and controls
75 lines (65 loc) · 3.06 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Global variables
# -------------------------------------
$taskName = "EmptyStandbyList"
$destinationFolder = "C:\EmptyStandbyList"
$localRecources = ".\Resources\"
$onlineResources = "https://raw.githubusercontent.com/Milton797/AutoEmptyStandbyList/master/Resources/"
# Change console title
# -------------------------------------
$Host.UI.RawUI.WindowTitle = "Manage ScheduledTask to $taskName"
# Self-elevate the script
# -------------------------------------
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
# Change the current working directory to the location of the script file
# -------------------------------------
Set-Location -Path (Split-Path -Parent $MyInvocation.MyCommand.Path)
# Functions
# -------------------------------------
function Register-AutoEmptyStandbyList {
New-Item -Path $destinationFolder -ItemType Directory -Force > $null
if (Test-Path $localRecources -PathType Container) {
Write-Host "Installing from offline resources."
$content = Get-Content ($localRecources + "EmptyStandbyList.xml") | Out-String
Copy-Item -Path ($localRecources + "EmptyStandbyList.exe") -Destination $destinationFolder -Force
} else {
Write-Host "Installing from online resources."
$content = (New-Object System.Net.WebClient).DownloadString(($onlineResources + "EmptyStandbyList.xml")) | Out-String
Invoke-WebRequest -Uri ($onlineResources + "EmptyStandbyList.exe") -OutFile ($destinationFolder + "\EmptyStandbyList.exe")
}
Register-ScheduledTask -TaskName "EmptyStandbyList" -Xml $content -Force > $null
Write-Host "Task registered successfully."
}
function Unregister-AutoEmptyStandbyList {
if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) {
Unregister-ScheduledTask -TaskName $taskName -Confirm:$False
Remove-Item -Path $destinationFolder -Recurse -Force
Write-Host "Task unregistered successfully."
} else {
Write-Host "The task '$taskName' does not exist."
}
}
# Menu
# -------------------------------------
while ($true) {
Clear-Host
Write-Host "Menu:"
Write-Host "[1] Register AutoEmptyStandbyList Task"
Write-Host "[2] Unregister AutoEmptyStandbyList Task"
Write-Host "[3] Quit"
$choice = Read-Host "Enter a menu option"
Clear-Host
switch ($choice) {
'1' { Register-AutoEmptyStandbyList }
'2' { Unregister-AutoEmptyStandbyList }
'3' { Write-Host "Exiting..." ; return }
default { Write-Host "Invalid option. Please select a valid option." }
}
Write-Host "Press any key continue..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').Key
}