Skip to content

Instantly share code, notes, and snippets.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment