|
Forum
|
|
|
Detect Administrator under Vista, how to detect if the program has been or has not been run as administrator so that a message is displayed?
|
|
| ragdog |
|

Extremely Active Member
     
Group: Moderators
Posts: 873
Member No.: 5019
Joined: 13-May 07

|
Hi Colin
Under xp works this for check "have user admin privileges" I´m not sure if this works under vista you can test it.
| CODE | ;-------------------------------------------------------------------- ; IsAdmin ; Returns TRUE if calling process (you) have Admin privileges and ; FALSE if you don't or in case of error. ; ; Copy IsAdmin proc and variables (except those starting with Msg) to ; your own program. ;--------------------------------------------------------------------
.486 .MODEL FLAT, STDCALL option casemap:none;case sensitive
include windows.inc include kernel32.inc include user32.inc include advapi32.inc includelib user32.lib includelib kernel32.lib includelib advapi32.lib
IsAdmin PROTO
.data MsgCaption db "IsAdmin", 0 MsgAdmin db "You have Admin privileges!", 0 MsgNoAdmin db "You don't have Admin privileges!", 0 hCurrentThread dd 0 hAccessToken dd 0 hCurrentProcess dd 0 dwInfoBufferSize dd 0 bSuccess dd 0 pInfoBuffer dd 0 siaNtAuthority SID_IDENTIFIER_AUTHORITY <SECURITY_NT_AUTHORITY> psidAdministrators dd 0
.data?
.const
.code Start: invoke IsAdmin .if eax == TRUE invoke MessageBox, NULL, ADDR MsgAdmin, ADDR MsgCaption, MB_OK .else invoke MessageBox, NULL, ADDR MsgNoAdmin, ADDR MsgCaption, MB_OK .endif invoke ExitProcess, 0 IsAdmin proc invoke GetCurrentThread mov hCurrentThread, eax invoke OpenThreadToken, hCurrentThread, TOKEN_QUERY, TRUE, ADDR hAccessToken .if eax == 0 invoke GetLastError .if eax != ERROR_NO_TOKEN mov eax, FALSE ret .endif invoke GetCurrentProcess mov hCurrentProcess, eax invoke OpenProcessToken, hCurrentProcess, TOKEN_QUERY, ADDR hAccessToken .if eax == 0 mov eax, FALSE ret .endif .endif invoke GetTokenInformation, hAccessToken, TokenGroups, NULL, NULL, ADDR dwInfoBufferSize .if dwInfoBufferSize > 0 invoke GlobalAlloc, GMEM_FIXED, dwInfoBufferSize mov pInfoBuffer, eax invoke GetTokenInformation, hAccessToken, TokenGroups, pInfoBuffer, dwInfoBufferSize, ADDR dwInfoBufferSize .endif mov bSuccess, eax invoke CloseHandle, hAccessToken
.if bSuccess == 0 mov eax, FALSE ret .endif
invoke AllocateAndInitializeSid, ADDR siaNtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, ADDR psidAdministrators .if eax == 0 mov eax, FALSE ret .endif mov bSuccess, FALSE mov ebx, pInfoBuffer mov ecx, TOKEN_GROUPS.GroupCount[ebx] xor esi, esi .while esi < ecx push esi push ecx mov ecx, TOKEN_GROUPS.Groups.Sid[ebx] mov eax, sizeof TOKEN_GROUPS.Groups xor edx, edx mul esi ;eax * esi -> eax add ecx, eax invoke EqualSid, psidAdministrators, ecx pop ecx pop esi .if eax != 0 mov bSuccess, TRUE .break .endif inc esi .endw invoke FreeSid, psidAdministrators invoke GlobalFree, pInfoBuffer mov eax, bSuccess ret IsAdmin endp end Start
|
Greets,
|
| |
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
|
|
|