LookupPrivilegeDisplayName (advapi32)
Last changed: anfortas.geo@yahoo.com-216.204.61.86

.
Summary
Returns the display name for a privilege when provided with the system name.

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern bool LookupPrivilegeDisplayName(
    string systemName,
    string privilegeName, //in
    System.Text.StringBuilder displayName,  // out
    ref uint cbDisplayName,
    out uint languageId
    );

VB Signature:

Declare Function LookupPrivilegeDisplayName Lib "advapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

If it returns false, you'll need to call Marshal.GetLastWin32Error() and handle at least these errors:

const int ERROR_INSUFFICIENT_BUFFER = 122;

This is one of those "call twice" functions, so this error is just daily life. When it returns with this error, the byte count (cbDisplayName) will be set to what you need. Call EnsureCapacity on your StringBuilder and go round again.

const int ERROR_NO_SUCH_PRIVILEGE = 1313;

The privileges that Windows knows about vary from one system to another. If you run your code on a Windows version other than the one you developed it on, you'll need to handle this one.

TODO Does anyone know where to find a definitive reference for which privileges are present on a given OS? There doesn't seem to be an enumeration function

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

Documentation