Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell から C# 経由でP/Invokeするサンプル。
$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
You can’t perform that action at this time.