🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages Started by Bogdan Sun, 30 Mar 2003 09:45
AdjustTokenPrivileges().
#17225
Author: Bogdan
Date: Sun, 30 Mar 2003 09:45
23 lines
1803 bytes
    I'm trying to shutdown Windows XP using ExitWindowsEx()
and I need to enable this privilege using AdjustTokenPrivileges().
    Does anyone know how to do this exactly(samplecode)?
I've tried the following code, but it seems it doesn't work.

//----------------------------------------------------------------
TOKEN_PRIVILEGES Privileges;
LUID_AND_ATTRIBUTES *Attributes=new LUID_AND_ATTRIBUTES[1];
bool Result=true;

LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,
                                  &(Attributes->Luid));
Attributes->Attributes=SE_PRIVILEGE_ENABLED;
Privileges.PrivilegeCount=1;
Privileges.Privileges=Attributes;
Result=AdjustTokenPrivileges(NULL,false,&Privileges,0,NULL,NULL);

if(Result==false) ShowMessage("AdjustTokenPrivileges() failed.");

ExitWindowsEx(EWX_SHUTDOWN,0);
//-----------------------------------------------------------------

Bogdan.
Re: AdjustTokenPrivileges().
#17229
Author: Nick B. Cassos
Date: Sun, 30 Mar 2003 14:19
36 lines
1952 bytes
Try the following code...

bool EnablePrivilege(const char *APrivilege)
{
    bool   Result = false;
    HANDLE AToken = INVALID_HANDLE_VALUE;

    if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES,
&AToken) != 0)
    {
        unsigned char ABuf[sizeof(TOKEN_PRIVILEGES ) +
sizeof(LUID_AND_ATTRIBUTES)];
        TOKEN_PRIVILEGES  *pBuf =(TOKEN_PRIVILEGES*) ABuf;

        if (LookupPrivilegeValue(NULL, APrivilege,
&pBuf->Privileges->Luid) != 0)
        {
            pBuf->PrivilegeCount         = 1;
            pBuf->Privileges->Attributes = SE_PRIVILEGE_ENABLED;

            if (AdjustTokenPrivileges(AToken, FALSE, pBuf, 0, NULL,
NULL) != 0)
            Result = true;
        }

        CloseHandle(AToken);
    }

    return Result;
}

On Sun, 30 Mar 2003 12:45:20 +0300, "Bogdan" <boprea@xnet.ro> wrote:

>    I'm trying to shutdown Windows XP using ExitWindowsEx()
>and I need to enable this privilege using AdjustTokenPrivileges().
>[snipped]
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