GetProcessDEPPolicy (kernel32)
Last changed: anonymous

.
Summary
Gets the data execution prevention (DEP) and DEP-ATL thunk emulation settings for the specified 32-bit process.

C# Signature:

[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr GetProcessDEPPolicy(IntPtr hProcess, out Policy lpFlags, out bool lpPermanent);

VB Signature:

Declare Function GetProcessDEPPolicy Lib "kernel32.dll" (TODO) As TODO

User-Defined Types:

None.

Policy:

[System.Flags]
public enum Policy : uint {
    DISABLED = 0x0,
    PROCESS_DEP_ENABLE = 0x00000001,
    PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION = 0x00000002
}

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

GetProcessDEPPolicy is supported for 32-bit processes only. If this function is called on a 64-bit process, it fails with ERROR_NOT_SUPPORTED.

Tips & Tricks:

Please add some!

Sample Code:

var result = default(Policy);
var per = false;
var policy = GetProcessDEPPolicy((IntPtr)(-1), out result, out per);
if(policy == default(IntPtr)) {
    throw new Win32Exception(Marshal.GetLastWin32Error());
}else {
    Console.WriteLine("Process DEP policy: " + result);
    Console.WriteLine("Permanent: " + per);
}

Documentation