mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-26 01:43:37 +01:00
Add lock-desktop.ps1 and suspend.ps1
This commit is contained in:
parent
d042c48c42
commit
969a457a15
@ -1,23 +1,19 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Enables hibernate mode for the local computer (needs admin rights)
|
Hibernates the computer
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script enables hibernate mode for the local computer. It needs admin rights.
|
This PowerShell script enables hibernate mode for the local computer immediately.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./hibernate
|
PS> ./hibernate
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz / License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
#Requires -RunAsAdministrator
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[Void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
"Bye bye."
|
||||||
[System.Windows.Forms.Application]::SetSuspendState("Hibernate", $false, $false);
|
& rundll32.exe powrprof.dll,SetSuspendState 1,1,0 # bHibernate,bForce,bWakeupEventsDisabled
|
||||||
|
|
||||||
"✔️ Done."
|
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
21
Scripts/lock-desktop.ps1
Normal file
21
Scripts/lock-desktop.ps1
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Locks the desktop
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script locks the local computer desktop immediately.
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./lock-desktop
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
try {
|
||||||
|
"Bye bye."
|
||||||
|
rundll32.exe user32.dll,LockWorkStation
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
@ -8,15 +8,14 @@
|
|||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz / License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Invoke-CimMethod -ClassName Win32_Operatingsystem -MethodName Win32Shutdown -Arguments @{ Flags = 0 }
|
Invoke-CimMethod -ClassName Win32_Operatingsystem -MethodName Win32Shutdown -Arguments @{ Flags = 0 }
|
||||||
|
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
21
Scripts/suspend.ps1
Normal file
21
Scripts/suspend.ps1
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Suspends the computer
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script suspends the local computer immediately.
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./suspend
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
try {
|
||||||
|
"Bye bye."
|
||||||
|
& rundll32.exe powrprof.dll,SetSuspendState 0,1,0 # bHibernate,bForce,bWakeupEventsDisabled
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
@ -10,7 +10,7 @@
|
|||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz / License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$RepoDir = "$PWD")
|
param([string]$RepoDir = "$PWD")
|
||||||
|
Loading…
Reference in New Issue
Block a user