diff --git a/Scripts/hibernate.ps1 b/Scripts/hibernate.ps1 index 21818f70..fa42994c 100755 --- a/Scripts/hibernate.ps1 +++ b/Scripts/hibernate.ps1 @@ -1,23 +1,19 @@ <# .SYNOPSIS - Enables hibernate mode for the local computer (needs admin rights) + Hibernates the computer .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 PS> ./hibernate .LINK https://github.com/fleschutz/PowerShell .NOTES - Author: Markus Fleschutz / License: CC0 + Author: Markus Fleschutz | License: CC0 #> -#Requires -RunAsAdministrator - try { - [Void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") - [System.Windows.Forms.Application]::SetSuspendState("Hibernate", $false, $false); - - "✔️ Done." + "Bye bye." + & rundll32.exe powrprof.dll,SetSuspendState 1,1,0 # bHibernate,bForce,bWakeupEventsDisabled exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/lock-desktop.ps1 b/Scripts/lock-desktop.ps1 new file mode 100644 index 00000000..15d400ff --- /dev/null +++ b/Scripts/lock-desktop.ps1 @@ -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 +} \ No newline at end of file diff --git a/Scripts/log-off.ps1 b/Scripts/log-off.ps1 index f54aad2e..3d8712de 100644 --- a/Scripts/log-off.ps1 +++ b/Scripts/log-off.ps1 @@ -8,15 +8,14 @@ .LINK https://github.com/fleschutz/PowerShell .NOTES - Author: Markus Fleschutz / License: CC0 + Author: Markus Fleschutz | License: CC0 #> try { Invoke-CimMethod -ClassName Win32_Operatingsystem -MethodName Win32Shutdown -Arguments @{ Flags = 0 } - exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/suspend.ps1 b/Scripts/suspend.ps1 new file mode 100644 index 00000000..1f0f0985 --- /dev/null +++ b/Scripts/suspend.ps1 @@ -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 +} \ No newline at end of file diff --git a/Scripts/sync-repo.ps1 b/Scripts/sync-repo.ps1 index 4f533535..ffcdcb4c 100644 --- a/Scripts/sync-repo.ps1 +++ b/Scripts/sync-repo.ps1 @@ -10,7 +10,7 @@ .LINK https://github.com/fleschutz/PowerShell .NOTES - Author: Markus Fleschutz / License: CC0 + Author: Markus Fleschutz | License: CC0 #> param([string]$RepoDir = "$PWD")