Article View: borland.public.cppbuilder.nativeapi
Article #17229Re: AdjustTokenPrivileges().
From: Nick B. Cassos
Date: Sun, 30 Mar 2003 14:19
Date: Sun, 30 Mar 2003 14:19
36 lines
1952 bytes
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]
Technical Details
Message-ID:
<h1vd8v4uqb84qagfh6qcd8s5corlqigp5g@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e86bcb3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ad601e127223a67e X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-30 06:21:20 PST From: Nick B. Cassos <nbc@no_spam.ath.forthnet.gr> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: AdjustTokenPrivileges(). Date: Sun, 30 Mar 2003 17:19:33 +0300 Message-ID: <h1vd8v4uqb84qagfh6qcd8s5corlqigp5g@4ax.com> References: <3e86bcb3@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.16.150.54 X-Trace: newsgroups.borland.com 1049033970 213.16.150.54 (30 Mar 2003 06:19:30 -0800) Lines: 37 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail