Created
August 14, 2023 09:58
-
-
Save tksst/2ebf7c346ee084bf674be06ea1d9a249 to your computer and use it in GitHub Desktop.
Windowsのスリープを妨害するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@powershell -NoProfile -ExecutionPolicy Unrestricted "&([ScriptBlock]::Create((cat \"%~f0\" | ?{$_.ReadCount -gt 1}) -join \"`n\"))" %* & goto:eof | |
$Signature = @' | |
[DllImport("kernel32.dll")] | |
public static extern int SetThreadExecutionState(int esFlags); | |
'@ | |
$Foo = Add-Type -MemberDefinition $Signature -Name "Bar" -Namespace Baz -PassThru | |
echo "NoSleep started. Press Ctrl+C to exit." | |
while ($true) { | |
Get-Date -Format "yyyy-MM-ddTHH:mm:ssK" | |
$result = $Foo::SetThreadExecutionState(1) | |
if ( $result -eq 0 ) { | |
echo "SetThreadExecutionState returns NULL" | |
} | |
Start-Sleep -s 50 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment