PHP Forum - Coding Board
Januar 22, 2018, 09:07:39 *
Willkommen Gast. Bitte einloggen oder registrieren.

Einloggen mit Benutzername, Passwort und Sitzungslänge
News:
 
   Übersicht   Hilfe Suche Einloggen Registrieren  
Seiten: [1]
  Drucken  
Autor Thema: Admin Rechte?  (Gelesen 116 mal)
0 Mitglieder und 1 Gast betrachten dieses Thema.
Syler
Sr. Member
****
Beiträge: 467



Profil anzeigen E-Mail
« am: September 19, 2008, 07:52:40 »

Code:
#include <windows.h>
#include <cstdio>
 
/*/////////////////////////////////////
//Has Admin rights?
*//////////////////////////////////////
BOOL IsAdmin()
{
UINT i;
bool bRetval = FALSE;
BOOL bSuccess;
HANDLE hAccessToken;
UCHAR InfoBuffer[1024];
PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS) InfoBuffer;
DWORD dwInfoBufferSize;
PSID psidAdministrators;
SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
OSVERSIONINFO Info = {0};
Info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&Info)) {
if ((Info.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)&&
(Info.dwMajorVersion==4))
return TRUE;
}
else return FALSE;
if (!OpenThreadToken(GetCurrentThread(),TOKEN_QUERY,TRUE,&hAccessToken)) {
if (GetLastError() != ERROR_NO_TOKEN)
return FALSE;
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hAccessToken))
return FALSE;
}
bSuccess = GetTokenInformation(hAccessToken,TokenGroups,InfoBuffer,
sizeof(InfoBuffer),&dwInfoBufferSize);
CloseHandle(hAccessToken);
if (!bSuccess)
return FALSE;
if (!AllocateAndInitializeSid(&siaNtAuthority,2,SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,0,0,0,0,0,0,&psidAdministrators))
return FALSE;
for (i = 0; i < ptgGroups->GroupCount; i++) {
if (EqualSid(psidAdministrators,ptgGroups->Groups[i].Sid)) {
bRetval = TRUE;
break;
}
}
FreeSid(psidAdministrators);
return bRetval;
}
 
int main(){
 
if (!IsAdmin){
printf(&quot;User is not an admin&quot;)
} else {
printf(&quot;User is an administrator&quot;)
}
return 0;
}

Syler
Gespeichert


Seiten: [1]
  Drucken  
 
Gehe zu:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2009, Simple Machines | New Look by Nolt Prüfe XHTML 1.0 Prüfe CSS