Skip to content

Instantly share code, notes, and snippets.

@tanaka-takayoshi
Created December 21, 2013 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaka-takayoshi/8066824 to your computer and use it in GitHub Desktop.
Save tanaka-takayoshi/8066824 to your computer and use it in GitHub Desktop.
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