Thread View: borland.public.cppbuilder.nativeapi
8 messages
8 total messages
Started by Jos�
Mon, 22 May 2006 16:11
WHat is my account type
Author: Jos�
Date: Mon, 22 May 2006 16:11
Date: Mon, 22 May 2006 16:11
4 lines
858 bytes
858 bytes
Is there a system call which tells me whether I am signed on as an administrator or as a limited user? -- Jos�
Re: WHat is my account type
Author: Mike Collins
Date: Mon, 22 May 2006 16:25
Date: Mon, 22 May 2006 16:25
21 lines
1656 bytes
1656 bytes
Yes and no, you can determine if your current account rights match those of the adminitration group. there are a number of steps to go through to do this: 1) call OpenProcessToken on the current process. 2) call GetTokenInformation on the returned handle 3) call AllocateAndInitializeSid to get information on the admin rights.. 4) use EqualSid to compare the two. I believe Remy posted some code here last year explaining how to do this, if not I can post my version which as I remember is based on his (it might actually be his...) HTH Mike "Jos�" <jose@127.0.0.1> wrote in message news:lko372tv8d3pmfa8aljurjaqc4st3e5g9n@4ax.com... > Is there a system call which tells me whether I am signed on as an > administrator or as a limited user? > -- > Jos�
Re: WHat is my account type
Author: Remy Lebeau (TeamB)
Date: Mon, 22 May 2006 17:11
Date: Mon, 22 May 2006 17:11
13 lines
1361 bytes
1361 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message news:4471e604@newsgroups.borland.com... > I believe Remy posted some code here last year explaining how to do > this, if not I can post my version which as I remember is based on his > (it might actually be his...) All code samples that I have ever posted are available and fully searchable in the newsgroup archives at http://www.deja.com Gambit
Re: WHat is my account type
Author: Jos�
Date: Mon, 22 May 2006 21:38
Date: Mon, 22 May 2006 21:38
15 lines
1448 bytes
1448 bytes
On Mon, 22 May 2006 10:11:39 -0700, "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote in borland.public.cppbuilder.nativeapi: >All code samples that I have ever posted are available and fully searchable >in the newsgroup archives at http://www.deja.com Well, I found a function named IsAdmin(void) It does one amazing thing: it requires no headers and it compiles immediately without error. It contains the functions by Mike. These are not found in the help file. Unfortunately the function seems to return true at all times. -- Jos�
Re: WHat is my account type
Author: Jos�
Date: Mon, 22 May 2006 21:42
Date: Mon, 22 May 2006 21:42
17 lines
1247 bytes
1247 bytes
On Mon, 22 May 2006 23:38:02 +0200, Jos� <jose@127.0.0.1> wrote in borland.public.cppbuilder.nativeapi: >Unfortunately the function seems to return true at all times. If you are so stupid to code if (IsAdmin) instead of if (IsAdmin()) Shame on me. -- Jos�
Re: WHat is my account type
Author: Remy Lebeau (TeamB)
Date: Mon, 22 May 2006 21:44
Date: Mon, 22 May 2006 21:44
22 lines
1675 bytes
1675 bytes
"Jos�" <jose@127.0.0.1> wrote in message news:0mb47250avbeh8vi81tmma1as7ugmjha6m@4ax.com... > Well, I found a function named IsAdmin(void) > > It does one amazing thing: it requires no headers The necessary headers are already included by the VCL by default. > It contains the functions by Mike. These are not found in the help file. As they are Microsoft functions, they are listed in Microsoft's documentation, not Borland's. The win32.hlp file does include all of them. > Unfortunately the function seems to return true at all times. The only way that can happen is if the code is run from a process that actually does have admin rights. Gambit
Re: WHat is my account type
Author: Colin B Maharaj
Date: Tue, 23 May 2006 22:16
Date: Tue, 23 May 2006 22:16
127 lines
4895 bytes
4895 bytes
Jos� wrote:
> Is there a system call which tells me whether I am signed on as an
> administrator or as a limited user?
No coded by Me but works for me...for the last 5 years on WinXP,NT, NT
Server, 2000 - NOT ME,98,95.
//------------------------------------------------------------
BOOL IsAdminLoggedOn(void)
{
HANDLE hToken;
DWORD dwStatus;
DWORD dwAccessMask;
DWORD dwAccessDesired;
DWORD dwACLSize;
DWORD dwStructureSize = sizeof(PRIVILEGE_SET);
PACL pACL = NULL;
PSID psidAdmin = NULL;
BOOL bReturn = FALSE;
PRIVILEGE_SET ps;
GENERIC_MAPPING GenericMapping;
PSECURITY_DESCRIPTOR psdAdmin = NULL;
SID_IDENTIFIER_AUTHORITY SystemSidAuthority = {SECURITY_NT_AUTHORITY};
int FM_ACCESS_READ = 1;
int FM_ACCESS_WRITE= 2;
try
{
// AccessCheck() requires an impersonation token.
ImpersonateSelf(SecurityImpersonation);
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE,
&hToken))
{
if (GetLastError() != ERROR_NO_TOKEN)
return false;
// If the thread does not have an access token, we'll
// examine the access token associated with the process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY,
&hToken))
return false;
}
if (!AllocateAndInitializeSid(&SystemSidAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &psidAdmin))
return false;
psdAdmin = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (psdAdmin == NULL)
return false;
if (!InitializeSecurityDescriptor(psdAdmin,
SECURITY_DESCRIPTOR_REVISION))
return false;
// Compute size needed for the ACL.
dwACLSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) +
GetLengthSid(psidAdmin) - sizeof(DWORD);
// Allocate memory for ACL.
pACL = (PACL)LocalAlloc(LPTR, dwACLSize);
if (pACL == NULL)
return false;
// Initialize the new ACL.
if (!InitializeAcl(pACL, dwACLSize, ACL_REVISION2))
return false;
dwAccessMask= FM_ACCESS_READ | FM_ACCESS_WRITE;
// Add the access-allowed ACE to the DACL.
if (!AddAccessAllowedAce(pACL, ACL_REVISION2,
dwAccessMask, psidAdmin))
return false;
// Set our DACL to the SD.
if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, pACL, FALSE))
return false;
// AccessCheck is sensitive about what is in the SD; set
// the group and owner.
SetSecurityDescriptorGroup(psdAdmin, psidAdmin, FALSE);
SetSecurityDescriptorOwner(psdAdmin, psidAdmin, FALSE);
if (!IsValidSecurityDescriptor(psdAdmin))
return false;
dwAccessDesired = FM_ACCESS_READ;
//
// Initialize GenericMapping structure even though we
// won't be using generic rights.
//
GenericMapping.GenericRead = FM_ACCESS_READ;
GenericMapping.GenericWrite = FM_ACCESS_WRITE;
GenericMapping.GenericExecute = 0;
GenericMapping.GenericAll = FM_ACCESS_READ | FM_ACCESS_WRITE;
if (!AccessCheck(psdAdmin, hToken, dwAccessDesired,
&GenericMapping, &ps, &dwStructureSize, &dwStatus,
&bReturn)) {
printf("AccessCheck() failed with error %lu\n", GetLastError());
return false;
}
RevertToSelf();
}
__finally
{
// Cleanup
if (pACL) LocalFree(pACL);
if (psdAdmin) LocalFree(psdAdmin);
if (psidAdmin) FreeSid(psidAdmin);
}
return bReturn;
}
//------------------------------------------------------------
Re: WHat is my account type
Author: Bob Gonder
Date: Sun, 28 May 2006 16:27
Date: Sun, 28 May 2006 16:27
10 lines
1231 bytes
1231 bytes
Jos� wrote: >Is there a system call which tells me whether I am signed on as an >administrator or as a limited user? You might look at BOOL IsUserAnAdmin(VOID); http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/isuseranadmin.asp
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads