FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Pedir autorizaci贸n de administrador de windows
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
Pedir autorizaci贸n de administrador de windows
Posted: Sun Apr 14, 2013 03:38 AM

驴Que debo hacer para que un programa que no se est谩 ejecutando como administrador pida la autorizaci贸n para poder modificar el registro de windows?

Saludos

Quique
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
Re: Pedir autorizaci贸n de administrador de windows
Posted: Wed Apr 17, 2013 12:50 AM

驴entonces no se puede con fivewin?

Saludos

Quique
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Pedir autorizaci贸n de administrador de windows
Posted: Wed Apr 17, 2013 06:51 AM
Quique,

Aqui parece estar la documentaci贸n necesaria de Windows:
http://msdn.microsoft.com/en-us/library/aa376389%28VS.85%29.aspx

Code (fw): Select all Collapse
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);
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
Re: Pedir autorizaci贸n de administrador de windows
Posted: Wed Apr 17, 2013 06:40 PM
Disculpa Antonio, pero mi ignorancia de C es mayor de lo que cualquiera puede imaginar, pero se me hizo facil hacer lo siguiente:

Pegarla debajo de otra funci贸n que tambi茅n tengo en C en el mismo programa cambiando la primera l铆na y agregando la linea hb_retc( b ); casi al final

Code (fw): Select all Collapse
//BOOL IsUserAdmin(VOID)
HB_FUNC( IsUserAdmin )
/*++
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);
}

hb_retl( b );
return(b);
}


y no compil贸 :-)

Code (fw): Select all Collapse
Warning W8061 ..\\fuentes\\main.prg 583: Initialization is only partially bracketed in function HB_FUN_IsUserAdmin
Warning W8081 ..\\fuentes\\main.prg 602: void functions may not return a value in function HB_FUN_IsUserAdmin

Error: Unresolved external '_HB_FUN_ISUSERADMIN' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN\BCC\MAIN.OBJ


Pero de cualquier manera, no estoy seguro que esa sea la respuesta, porque lo que necesito es que el programa pida la autorizaci贸n de administrador como lo hace cualquier programa de instalaci贸n, aunque en este caso no es instalaci贸n, 煤nicamente es para escribir en el registro de windows, y seg煤n entiendo, lo 煤nico que hace esta funci贸n es devolver si el usuario es administrador.
Saludos

Quique

Continue the discussion