-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepTimer-Simple.ps1
More file actions
62 lines (53 loc) · 2.07 KB
/
Copy pathSleepTimer-Simple.ps1
File metadata and controls
62 lines (53 loc) · 2.07 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
# Sleep Timer Pro - Simple Version
param(
[int]$Minutes = 30,
[string]$Action = "Sleep"
)
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Text = "Sleep Timer Pro"
$form.Size = New-Object System.Drawing.Size(400, 300)
$form.StartPosition = "CenterScreen"
$label = New-Object System.Windows.Forms.Label
$label.Text = "Sleep Timer - $Minutes minutes`nAction: $Action"
$label.Font = New-Object System.Drawing.Font("Segoe UI", 14)
$label.Size = New-Object System.Drawing.Size(350, 60)
$label.Location = New-Object System.Drawing.Point(20, 20)
$form.Controls.Add($label)
$startBtn = New-Object System.Windows.Forms.Button
$startBtn.Text = "START TIMER"
$startBtn.Size = New-Object System.Drawing.Size(150, 40)
$startBtn.Location = New-Object System.Drawing.Point(120, 100)
$startBtn.Font = New-Object System.Drawing.Font("Segoe UI", 12, [System.Drawing.FontStyle]::Bold)
$startBtn.BackColor = [System.Drawing.Color]::FromArgb(0, 120, 212)
$startBtn.ForeColor = [System.Drawing.Color]::White
$startBtn.Add_Click({
$startBtn.Enabled = $false
$startBtn.Text = "RUNNING..."
$seconds = $Minutes * 60
for ($i = $seconds; $i -gt 0; $i--) {
$min = [math]::Floor($i / 60)
$sec = $i % 60
$label.Text = "Time remaining: {0:D2}:{1:D2}`nAction: $Action" -f $min, $sec
$form.Refresh()
Start-Sleep -Seconds 1
}
$label.Text = "Executing $Action..."
$form.Refresh()
Start-Sleep -Seconds 2
switch ($Action) {
"Sleep" { rundll32.exe powrprof.dll,SetSuspendState 0,1,0 }
"Shutdown" { Stop-Computer -Force }
"Restart" { Restart-Computer -Force }
"Hibernate" { rundll32.exe powrprof.dll,SetSuspendState 1,1,0 }
}
$form.Close()
})
$form.Controls.Add($startBtn)
$cancelBtn = New-Object System.Windows.Forms.Button
$cancelBtn.Text = "Cancel"
$cancelBtn.Size = New-Object System.Drawing.Size(100, 30)
$cancelBtn.Location = New-Object System.Drawing.Point(145, 160)
$cancelBtn.Add_Click({ $form.Close() })
$form.Controls.Add($cancelBtn)
$form.ShowDialog()