Skip to content

Instantly share code, notes, and snippets.

@kernullist
Created November 15, 2019 05:43
Show Gist options
  • Select an option

  • Save kernullist/e84e5c2b45b12b9a88b528e0ed2161cd to your computer and use it in GitHub Desktop.

Select an option

Save kernullist/e84e5c2b45b12b9a88b528e0ed2161cd to your computer and use it in GitHub Desktop.
PowerShell Win32 API Usage #01
$FunctionSig = @"
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(uint access, bool inherit, uint pid);
"@
$kernel32 = Add-Type -MemberDefinition $FunctionSig -Name "Process" -Namespace Win32Functions -PassThru
$kernel32::OpenProcess(0x1000, $false, 7520)
@kernullist
Copy link
Author

$handle = $kernel32::OpenProcess(0x1000, $false, 7520)
$handle.ToString("X8")

@kernullist
Copy link
Author

$FunctionSig = @"
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(uint access, bool inherit, uint pid);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr handle);
"@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment