Created
December 21, 2013 08:21
-
-
Save tanaka-takayoshi/8066824 to your computer and use it in GitHub Desktop.
PowerShell から C# 経由でP/Invokeするサンプル。
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
$signature = @" | |
[DllImport("kernel32.dll", SetLastError = true)] | |
public static extern Boolean GetSystemPowerStatus(out SystemPowerStatus sps); | |
public struct SystemPowerStatus | |
{ | |
public Byte ACLineStatus; | |
public Byte BatteryFlag; | |
public Byte BatteryLifePercent; | |
public Byte Reserved1; | |
public Int32 BatteryLifeTime; | |
public Int32 BatteryFullLifeTime; | |
} | |
"@ | |
Add-Type -MemberDefinition $signature -Name PowerStatus -Namespace PowerStatus | |
$systemPowerStatus = New-Object PowerStatus.PowerStatus+SystemPowerStatus | |
[void][PowerStatus.PowerStatus]::GetSystemPowerStatus([ref]$systemPowerStatus) | |
$systemPowerStatus | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment