Skip to content

Instantly share code, notes, and snippets.

@zxlooong
Created September 23, 2014 07:10
Show Gist options
  • Save zxlooong/26a5a67ea67fc574b80f to your computer and use it in GitHub Desktop.
Save zxlooong/26a5a67ea67fc574b80f to your computer and use it in GitHub Desktop.
windows 相关操作
BOOL CWyPassEdit::IsAdministrator()
{
//判断是否管理员模式
BOOL bIsElevated = FALSE;
HANDLE hToken = NULL;
UINT16 uWinVer = LOWORD(GetVersion());
uWinVer = MAKEWORD(HIBYTE(uWinVer),LOBYTE(uWinVer));
if (uWinVer < 0x0600)//不是VISTA、Windows7
{
bIsElevated = TRUE;
return bIsElevated;
}
if (OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken))
{
DWORD TokenIsElevated;
DWORD dwReturnLength = 0;
if (GetTokenInformation(hToken,/*TokenElevation*/(_TOKEN_INFORMATION_CLASS)20,&TokenIsElevated,sizeof(DWORD),&dwReturnLength))
{
if (dwReturnLength == sizeof(DWORD)&&(TokenIsElevated == 1))
bIsElevated = TRUE;
}
CloseHandle( hToken );
hToken = NULL;
}
return bIsElevated;
}
BOOL CWyPassEdit::IsIE()
{
BOOL bIE = TRUE;
char szFileFullPath[256] = {0};
::GetModuleFileNameA(NULL,static_cast<LPSTR>(szFileFullPath),256);
if(std::strstr(szFileFullPath, "iexplore.exe") == NULL)
{
bIE = FALSE;
}
return bIE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment