Wow
An old theme revived !
To be honest, I didn't expect to see so many replies here. Thanks everyone.
ChrisR, see if it works for you.
Code: Select all
EnableExplicit
Prototype.i CheckTokenMembership(TokenHandle, pSidToCheck, pIsMember)
Global CheckTokenMembership.CheckTokenMembership
Prototype.i AllocateAndInitializeSid(pIdentifierAuthority, nSubAuthorityCount, dwSubAuthority0, dwSubAuthority1, dwSubAuthority2, dwSubAuthority3, dwSubAuthority4, dwSubAuthority5, dwSubAuthority6, dwSubAuthority7, pSid)
Global AllocateAndInitializeSid.AllocateAndInitializeSid
Prototype.i FreeSid(pSid)
Global FreeSid.FreeSid
Procedure GetAdminLevel()
Protected dll
Protected bIsAdmin.l, bIsToken.l
Protected pSidAdministrator, pSidSystem, pSidTrustedInstaller
Protected NtAuthority.SID_IDENTIFIER_AUTHORITY
NtAuthority\Value[5]=5 ; SECURITY_NT_AUTHORITY
dll=OpenLibrary(#PB_Any,"advapi32.dll")
If dll
CheckTokenMembership = GetFunction(dll,"CheckTokenMembership")
If CheckTokenMembership
AllocateAndInitializeSid = GetFunction(dll, "AllocateAndInitializeSid")
If AllocateAndInitializeSid
FreeSid = GetFunction(dll, "FreeSid")
If FreeSid
AllocateAndInitializeSid(@NtAuthority,
2,
#SECURITY_BUILTIN_DOMAIN_RID,
#DOMAIN_ALIAS_RID_ADMINS,
0,
0,
0,
0,
0,
0,
@pSidAdministrator)
AllocateAndInitializeSid(@NtAuthority,
1,
#SECURITY_LOCAL_SYSTEM_RID,
0,
0,
0,
0,
0,
0,
0,
@pSidSystem)
#SECURITY_SERVICE_ID_RID_COUNT = 6
#SECURITY_SERVICE_ID_BASE_RID = $50
#SECURITY_TRUSTED_INSTALLER_RID1 = 956008885
#SECURITY_TRUSTED_INSTALLER_RID2 = 3418522649
#SECURITY_TRUSTED_INSTALLER_RID3 = 1831038044
#SECURITY_TRUSTED_INSTALLER_RID4 = 1853292631
#SECURITY_TRUSTED_INSTALLER_RID5 = 2271478464
AllocateAndInitializeSid(@NtAuthority,
#SECURITY_SERVICE_ID_RID_COUNT,
#SECURITY_SERVICE_ID_BASE_RID,
#SECURITY_TRUSTED_INSTALLER_RID1,
#SECURITY_TRUSTED_INSTALLER_RID2,
#SECURITY_TRUSTED_INSTALLER_RID3,
#SECURITY_TRUSTED_INSTALLER_RID4,
#SECURITY_TRUSTED_INSTALLER_RID5,
0,
0,
@pSidTrustedInstaller)
CheckTokenMembership(#Null, pSidAdministrator, @bIsToken)
If bIsToken : bIsAdmin = 1 : EndIf
bIsToken = 0
CheckTokenMembership(#Null, pSidSystem, @bIsToken)
If bIsToken : bIsAdmin = 2 : EndIf
bIsToken = 0
CheckTokenMembership(#Null, pSidTrustedInstaller, @bIsToken)
If bIsToken : bIsAdmin = 3 : EndIf
FreeSid(pSidAdministrator)
FreeSid(pSidSystem)
FreeSid(pSidTrustedInstaller)
EndIf
EndIf
EndIf
CloseLibrary(dll)
EndIf
ProcedureReturn bIsAdmin
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
Debug GetAdminLevel()
CompilerEndIf
AZJIO, thank you.
I have already seen this code.
fryquez, thank you too.
It will be very helpful.
JHPJHP, thank you.
I really appreciate your contribution, but...
I used to be able to look at your work without any problems, including the source codes. But since some time it became impossible. I'm sorry.
P.S. Sorry, this popup is a bit confusing.
Anyway, thanks for not passing by this topic.