मेरे Vista एप्लिकेशन को यह जानने की आवश्यकता है कि उपयोगकर्ता ने इसे "व्यवस्थापक के रूप में" (उन्नत) या मानक उपयोगकर्ता (गैर-उन्नत) के रूप में लॉन्च किया है या नहीं। रनवे पर मैं इसका पता कैसे लगा सकता हूं? वहाँ "क्रॉस प्रौद्योगिकी नमूने" का एक भाग के रूप में एक "UACDemo" अनुप्रयोग हैमैं कैसे पता लगा सकता हूं कि मेरी प्रक्रिया यूएसी-उन्नत है या नहीं?
HRESULT GetElevationType(__out TOKEN_ELEVATION_TYPE * ptet);
/*
Parameters:
ptet
[out] Pointer to a variable that receives the elevation type of the current process.
The possible values are:
TokenElevationTypeDefault - This value indicates that either UAC is disabled,
or the process is started by a standard user (not a member of the Administrators group).
The following two values can be returned only if both the UAC is enabled
and the user is a member of the Administrator's group:
TokenElevationTypeFull - the process is running elevated.
TokenElevationTypeLimited - the process is not running elevated.
Return Values:
If the function succeeds, the return value is S_OK.
If the function fails, the return value is E_FAIL. To get extended error information, call GetLastError().
Implementation:
*/
HRESULT GetElevationType(__out TOKEN_ELEVATION_TYPE * ptet)
{
if (!IsVista())
return E_FAIL;
HRESULT hResult = E_FAIL; // assume an error occurred
HANDLE hToken = NULL;
if (!::OpenProcessToken(
::GetCurrentProcess(),
TOKEN_QUERY,
&hToken))
{
return hResult;
}
DWORD dwReturnLength = 0;
if (::GetTokenInformation(
hToken,
TokenElevationType,
ptet,
sizeof(*ptet),
&dwReturnLength))
{
ASSERT(dwReturnLength == sizeof(*ptet));
hResult = S_OK;
}
::CloseHandle(hToken);
return hResult;
}
IsUserAnAdmin समारोह भी उपयोगी हो सकता है ऊपर उठाया है। http://msdn.microsoft.com/en-us/library/windows/desktop/bb776463%28v=vs.85%29.aspx – jmnben