windows admin or limited.

BlitzMax Forums/BlitzMax Beginners Area/windows admin or limited.

is there a way to find out if a windows user has limited or admin rights on a computer?

How's about

http://support.microsoft.com/kb/q118626/

and

http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx

thanks Brucey, but I think I need a little bit more help than that. I have no idea how to convert or adopt that to BMAX. My knowledge of c is far more limited.

Alright, the C code could be adapted to BlitzMax but it's easier to just use the sample's function. So,

admin.c

#include <windows.h>

int IsUserAdmin(VOID)
{
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);
}


test.bmx

Strict

Import "admin.c"

Extern
	Function IsUserAdmin()
End Extern

If IsUserAdmin()
	Notify "You have the power!"
Else
	Notify "You don't have the power..."
EndIf


Give that a shot, I'm not sure it will work as I can't test it right now but that's the basic idea.

thanks Khomy Prime, as soon as I work it out I'll let you know. Really apreciated.

Khomy, I tried the code above but I get this errors:
C:/Documents and Settings/Jesse/My Documents/admin/.bmx/admin.c.console.release.win32.x86.o:admin.c:(.text+0x36): undefined reference to `AllocateAndInitializeSid@44'
C:/Documents and Settings/Jesse/My Documents/admin/.bmx/admin.c.console.release.win32.x86.o:admin.c:(.text+0x4b): undefined reference to `CheckTokenMembership'
C:/Documents and Settings/Jesse/My Documents/admin/.bmx/admin.c.console.release.win32.x86.o:admin.c:(.text+0x61): undefined reference to `FreeSid@4'
C:/Program Files/BlitzMax/lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16'
Build Error: Failed to link C:/Documents and Settings/Jesse/My Documents/admin/admin.exe


Strange, ok, try adding,
#include <winbase.h>

after
#include <windows.h>

That should fix the first three errors.

The last error is a result of you trying to execute the C code directly. You have to save those two files in the same folder and compile/run test.bmx.

it managed to clear those errors but now it doesn't seem to recognize:
"CheckTokenMembership" it apperst it is not defined in windows.h or winbase.h