User forums > Using Code::Blocks
Win: IsUserAnAdmin() and CheckTokenMembership(..)
jmb:
Hi
In VisualStudioExpress-c++ there is an function "IsUserAnAdmin()" available.
But it doesn't work in codeblocks. So I found the following solution in the net:
(Its for testing, whether an user is Admin)
--- Code: ---BOOL IsUserAdmin(VOID)
/*++
Routine Description: This routine returns TRUE if the caller's
process is a member of the Administrators local group. Caller is NOT
expected to be impersonating anyone and is expected to be able to
open its own process and process token.
Arguments: None.
Return Value:
TRUE - Caller has Administrators local group.
FALSE - Caller does not have Administrators local group. --
*/
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
--- End code ---
But I just get this:
undefined reference to `CheckTokenMembership(void*, void*, int*)@12'
Any Idea what to do ?
MortenMacFly:
--- Quote from: jmb on January 20, 2015, 12:33:20 pm ---Any Idea what to do ?
--- End quote ---
1.) Google for the error.
2.) Respect the forum rules. This is a C::B forum and not a general programming forum.
I'll give you a hint anyways:
As seen on:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376389%28v=vs.85%29.aspx
...does CheckTokenMembership require to link against Advapi32 in the right order.
jmb:
--- Quote from: MortenMacFly on January 20, 2015, 12:58:52 pm ---
--- Quote from: jmb on January 20, 2015, 12:33:20 pm ---Any Idea what to do ?
--- End quote ---
1.) Google for the error.
--- End quote ---
I did that. See below ...
--- Quote ---2.) Respect the forum rules. This is a C::B forum and not a general programming forum.
--- End quote ---
Sorry. But for me this question has to do specifically with the usage of codeblocks. I didn't asked anything about programming. I asked about that specific problem I have in codeblocks. This was the reason, why I mentioned VisualStudio.
--- Quote ---I'll give you a hint anyways:
As seen on:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376389%28v=vs.85%29.aspx
...does CheckTokenMembership require to link against Advapi32 in the right order.
--- End quote ---
Thank you. But I found that by myself. I can't find that ".lib." So I tried to add the
libadvapi32.a in the section "Linker-Settings". It doesn't work.
I've just begun to work with codeblocks yesterday. So sorry, if that question is a bit nooby.
Jenna:
--- Quote from: jmb on January 20, 2015, 01:27:58 pm ---Sorry. But for me this question has to do specifically with the usage of codeblocks. I didn't asked anything about programming. I asked about that specific problem I have in codeblocks. This was the reason, why I mentioned VisualStudio.
--- End quote ---
In this case please (reread) the forum rules.
Please also read this wiki-entry: http://wiki.codeblocks.org/index.php?title=FAQ-General#Q:_What_Code::Blocks_is_not.3F .
By the way, you can also use VC's commandline version as compiler in Code::Blocks.
jmb:
ok, so I was totally wrong about my expectations about the forum. My first Idea was, as I mentioned above, that this forum will
discuss all topics around the usage of that IDE. I thought, this includes how to set up compilers and linkers, too.
During my investigations I found things like : "in this and that IDE it is handled so and so. I dont know, how it works in codeblocks.."
My next step was then to search for an codeblocks-forum *shrugs*
Navigation
[0] Message Index
[#] Next page
Go to full version