Article View: borland.public.cppbuilder.nativeapi
Article #9519Re: ExitWindowsEx
From: Edward
Date: Wed, 07 Jul 2004 03:03
Date: Wed, 07 Jul 2004 03:03
62 lines
2480 bytes
2480 bytes
Try this:
and do not forget #include <shellapi.h>
TOKEN_PRIVILEGES wTokenIn, wTokenOut;
DWORD wLength;
HANDLE wCurrentProcess, wToken;
_LUID wLuid;
OSVERSIONINFO wOsVer;
try
{
wCurrentProcess = GetCurrentProcess();
OpenProcessToken(wCurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&wToken);
LookupPrivilegeValue(NULL, "SeShutdownPrivilege", &wLuid);
wTokenIn.PrivilegeCount = 1;
wTokenIn.Privileges[0].Luid = wLuid;
wTokenIn.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(wToken, FALSE, &wTokenIn,
sizeof(TOKEN_PRIVILEGES), &wTokenOut,&wLength);
CloseHandle(wToken);
}
__finally
{
Application->ProcessMessages();
if (1)
ExitWindowsEx(EWX_REBOOT | EWX_FORCEIFHUNG, 0);
else
{
wOsVer.dwOSVersionInfoSize = sizeof(wOsVer);
GetVersionEx(&wOsVer);
if (wOsVer.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCEIFHUNG, 0);
else
ExitWindowsEx(EWX_POWEROFF | EWX_FORCEIFHUNG, 0);
}
}
"Brent" <nospam@nospam.com> escreveu na mensagem
news:40eb5ae2$1@newsgroups.borland.com...
> Hi All,
>
> ExitWindowsEx(EWX_SHUTDOWN, 0);
>
> I want to use the above code to turn the computer off. On XP, the program
> will only shut down to the login screen. How do I ensure that the program
> has the SE_SHUTDOWN_NAME privilege set? Is it something I can do within
the
> application.
>
> Any help greatly appreciated.
>
> thanks,
>
> Brent
>
>
>
Technical Details
Message-ID:
<40eb6806$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40eb5ae2$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,877cf1e5dc319316 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Edward" <Registrados2004@aol.com> From: "Edward" <Registrados2004@aol.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40eb5ae2$1@newsgroups.borland.com> Subject: Re: ExitWindowsEx Date: Wed, 7 Jul 2004 00:03:33 -0300 Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 200.213.49.155 Message-ID: <40eb6806$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089169414 200.213.49.155 (6 Jul 2004 20:03:34 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail