User rights on a Vista OS
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
User rights on a Vista OS
Hi,
is there any way to know if the current user has the administrator rights or if it has only limited rights on a Vista OS ?
I need to know it because my app create a virtual printer at runtime so I have to check if the user has the administrator rights before create the printer to avoid a system erron if the user is not the administrator. Unfortunately on a Windows Vista OS only the administrator can add a new printer.
Thanks in advance
Best Regards,
Marco Turco
is there any way to know if the current user has the administrator rights or if it has only limited rights on a Vista OS ?
I need to know it because my app create a virtual printer at runtime so I have to check if the user has the administrator rights before create the printer to avoid a system erron if the user is not the administrator. Unfortunately on a Windows Vista OS only the administrator can add a new printer.
Thanks in advance
Best Regards,
Marco Turco
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
Marco,
here is small function from Enrico. (not tested)
here is small function from Enrico. (not tested)
Code: Select all | Expand
#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>
#include <CommDlg.h>
extern LPSTR LToStr( long w );
HARBOUR HB_FUN_ISADMIN( PARAMS )
{
HANDLE hToken;
PTOKEN_GROUPS pGroupInfo;
DWORD dwSize = 0, dwResult;
DWORD nError = 0, i;
BOOL lError, lAdMin = FALSE;
LPSTR cFunc = "";
PSID psidAdmin;
CHAR cMess[200];
SID_IDENTIFIER_AUTHORITY SystemSidAuthority= SECURITY_NT_AUTHORITY;
if ( lError = (! OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken) ))
{
cFunc = "OpenProcessToken";
nError = GetLastError();
if (nError == ERROR_CALL_NOT_IMPLEMENTED)
{
_retl( TRUE );
return;
}
}
if ( ! lError && ! GetTokenInformation(hToken, TokenGroups, NULL, dwSize, &dwSize))
{
dwResult = GetLastError();
if( lError=(dwResult != ERROR_INSUFFICIENT_BUFFER ))
{
nError = dwResult;
cFunc = "GetTokenInformation";
}
}
if ( ! lError )
{
pGroupInfo = (PTOKEN_GROUPS) GlobalAlloc( GPTR, dwSize );
if( lError = (! GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize ) ))
{
nError = GetLastError();
cFunc = "GetTokenInformation";
}
}
if ( ! lError )
if ( lError = (! AllocateAndInitializeSid ( &SystemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin) ))
{
nError = GetLastError();
cFunc = "AllocateAndInitializeSid";
}
if ( ! lError )
{
for( i=0; i<pGroupInfo->GroupCount; i++)
{
if ( EqualSid(psidAdmin, pGroupInfo->Groups[i].Sid) )
{
lAdMin = TRUE;
break;
}
}
}
else
{
cMess[0]=0;
lstrcat(cMess,"Error calling ");
lstrcat(cMess,cFunc);
lstrcat(cMess,": ");
lstrcat(cMess,LToStr(nError));
MessageBox(GetActiveWindow(),cMess,"Attention", MB_OK);
}
if (psidAdmin)
FreeSid(psidAdmin);
if ( pGroupInfo )
GlobalFree( pGroupInfo );
CloseHandle( hToken );
_retl( lAdMin );
}
kind regards
Stefan
Stefan
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
- Enrico Maria Giordano
- Posts: 8767
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42595
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 38 times
- Been thanked: 86 times
- Contact:
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
-
- Posts: 824
- Joined: Thu Oct 13, 2005 7:39 am
- Location: Germany
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
- lucasdebeltran
- Posts: 1303
- Joined: Tue Jul 21, 2009 8:12 am
- Contact:
Re: User rights on a Vista OS
Hi,
Is there any newest function?.
This is my code:
But I get some warnings:
Warning W8060 test.prg 41: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 55: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 65: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 73: Possibly incorrect assignment in function HB_FUN_ISADMIN
Line 41:
if ( lError = (! OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken) ))
Line 55:
if( lError=(dwResult != ERROR_INSUFFICIENT_BUFFER ))
Line 65:
if( lError = (! GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize ) ))
Line 73:
if ( lError = (! AllocateAndInitializeSid ( &SystemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin) ))
Thanks a lot.
Is there any newest function?.
This is my code:
Code: Select all | Expand
#pragma BEGINDUMP
#include <hbapi.h>
#include <Windows.h>
#include <CommDlg.h>
extern LPSTR LToStr( long w );
HB_FUNC( ISADMIN )
{
HANDLE hToken;
PTOKEN_GROUPS pGroupInfo;
DWORD dwSize = 0, dwResult;
DWORD nError = 0, i;
BOOL lError, lAdMin = FALSE;
LPSTR cFunc = "";
PSID psidAdmin;
CHAR cMess[200];
SID_IDENTIFIER_AUTHORITY SystemSidAuthority= SECURITY_NT_AUTHORITY;
if ( lError = (! OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken) ))
{
cFunc = "OpenProcessToken";
nError = GetLastError();
if (nError == ERROR_CALL_NOT_IMPLEMENTED)
{
hb_retl( TRUE );
return;
}
}
if ( ! lError && ! GetTokenInformation(hToken, TokenGroups, NULL, dwSize, &dwSize))
{
dwResult = GetLastError();
if( lError=(dwResult != ERROR_INSUFFICIENT_BUFFER ))
{
nError = dwResult;
cFunc = "GetTokenInformation";
}
}
if ( ! lError )
{
pGroupInfo = (PTOKEN_GROUPS) GlobalAlloc( GPTR, dwSize );
if( lError = (! GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize ) ))
{
nError = GetLastError();
cFunc = "GetTokenInformation";
}
}
if ( ! lError )
if ( lError = (! AllocateAndInitializeSid ( &SystemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin) ))
{
nError = GetLastError();
cFunc = "AllocateAndInitializeSid";
}
if ( ! lError )
{
for( i=0; i<pGroupInfo->GroupCount; i++)
{
if ( EqualSid(psidAdmin, pGroupInfo->Groups[i].Sid) )
{
lAdMin = TRUE;
break;
}
}
}
else
{
cMess[0]=0;
lstrcat(cMess,"Error calling ");
lstrcat(cMess,cFunc);
lstrcat(cMess,": ");
lstrcat(cMess,LToStr(nError));
MessageBox(GetActiveWindow(),cMess,"Attention", MB_OK);
}
if (psidAdmin)
FreeSid(psidAdmin);
if ( pGroupInfo )
GlobalFree( pGroupInfo );
CloseHandle( hToken );
hb_retl( lAdMin );
}
#pragma ENDDUMP
But I get some warnings:
Warning W8060 test.prg 41: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 55: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 65: Possibly incorrect assignment in function HB_FUN_ISADMIN
Warning W8060 test.prg 73: Possibly incorrect assignment in function HB_FUN_ISADMIN
Line 41:
if ( lError = (! OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken) ))
Line 55:
if( lError=(dwResult != ERROR_INSUFFICIENT_BUFFER ))
Line 65:
if( lError = (! GetTokenInformation(hToken, TokenGroups, pGroupInfo, dwSize, &dwSize ) ))
Line 73:
if ( lError = (! AllocateAndInitializeSid ( &SystemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin) ))
Thanks a lot.
Muchas gracias. Many thanks.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
- Enrico Maria Giordano
- Posts: 8767
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
- lucasdebeltran
- Posts: 1303
- Joined: Tue Jul 21, 2009 8:12 am
- Contact:
Re: User rights on a Vista OS
Hi,
I would prefer not.
Maybe ANtonio could help please to indicate how to fix it.
I would prefer not.
Maybe ANtonio could help please to indicate how to fix it.
Muchas gracias. Many thanks.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
- Enrico Maria Giordano
- Posts: 8767
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: User rights on a Vista OS
I think you cannot avoid them. The compiler is warning you that you are assigning
lError = ...
while it thinks that you did mean
lError == ...
but it's not what you want to do as you're intentionally doing an assignment.
EMG
lError = ...
while it thinks that you did mean
lError == ...
but it's not what you want to do as you're intentionally doing an assignment.
EMG
- lucasdebeltran
- Posts: 1303
- Joined: Tue Jul 21, 2009 8:12 am
- Contact:
Re: User rights on a Vista OS
Antonio,
Please can you help me with C code?.
Also, it would be very interesting to include this function into FWH!!!.
Please can you help me with C code?.
Also, it would be very interesting to include this function into FWH!!!.
Muchas gracias. Many thanks.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
- Enrico Maria Giordano
- Posts: 8767
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
- Lautaro
- Posts: 327
- Joined: Fri Oct 07, 2005 2:44 pm
- Location: Osorno, Chile
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Re: User rights on a Vista OS
Hello,
Harbour have WAPI_ISUSERANADMIN() funcion in hbwin.
Best regards,
Lautaro
Harbour have WAPI_ISUSERANADMIN() funcion in hbwin.
Best regards,
Lautaro