# Include
<
Windows. h
>
# Include
<
Stdio. h
>
Bool isadmin (
Void
);
Int
Main (
Int
Argc,
Char
*
Argv [])
{
If
(Isadmin ())
Printf (
"
Isadmin-true
"
);
Else
Printf (
"
Isadmin-false
"
);
Return
0;
}
Bool isadmin (
Void
)
{
Handle haccesstoken;
Byte
*
Infobuffer;
Ptoken_groups ptggroups;
DWORD dwinfobuffersize;
Psid psidadministrators;
Sid_identifier_authority siantauthority
=
Security_nt_authority;
Uint I;
Bool Bret
=
False;
If
(
!
Openprocesstoken (getcurrentprocess (), token_query,
&
Haccesstoken ))
Goto
Cleanup;
Infobuffer
=
New
Byte [
1024
];
If
(
!
Infobuffer)
Goto
Cleanup;
Bret
=
Gettokeninformation (haccesstoken,
Tokengroups,
Infobuffer,
1024
,
&
Dwinfobuffersize );
Closehandle (haccesstoken );
If
(
!
Bret)
Goto
Cleanup;
If
(
!
Allocateandinitializesid (
&
Siantauthority,
2
,
Security_builtin_domain_rid,
Domain_alias_rid_admins,
0
,
0
,
0
,
0
,
0
,
0
,
&
Psidadministrators ))
Goto
Cleanup;
Bret
=
False;
Ptggroups
=
(Ptoken_groups) infobuffer;
For
(I
=
0
; I
<
Ptggroups
->
Groupcount; I
++
)
{
If
(Partition Sid (psidadministrators, ptggroups
->
Groups [I]. Sid ))
{
Bret
=
True;
Break
;
}
}
Freesid (psidadministrators );
Cleanup:
If
(Infobuffer)
Delete infobuffer;
Return
Bret;
}