Skip to content

Instantly share code, notes, and snippets.

@tksst
Created August 14, 2023 09:58
Show Gist options
  • Save tksst/2ebf7c346ee084bf674be06ea1d9a249 to your computer and use it in GitHub Desktop.
Save tksst/2ebf7c346ee084bf674be06ea1d9a249 to your computer and use it in GitHub Desktop.
Windowsのスリープを妨害するスクリプト
@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