Article View: borland.public.cppbuilder.nativeapi
Article #9449Re: ExitWindowsEx
From: Brent
Date: Wed, 07 Jul 2004 23:25
Date: Wed, 07 Jul 2004 23:25
82 lines
3098 bytes
3098 bytes
Hi Edward,
I gave it a go, but unfortunately it didn't work. But the code has put me
into the right area for research. Had a look at the AdjustTokenPrivileges
API function, and it said that it can not add privileges, only enable of
disable existing privileges for an application.
Looks like I'm playing catchup from Win95 to WinXP.
cheers, and thanks for the help.
Brent
"Edward" <Registrados2004@aol.com> wrote in message
news:40eb6806$1@newsgroups.borland.com...
> 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:
<40ec8643@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40eb5ae2$1@newsgroups.borland.com> <40eb6806$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 From: "Brent" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40eb5ae2$1@newsgroups.borland.com> <40eb6806$1@newsgroups.borland.com> Subject: Re: ExitWindowsEx Date: Thu, 8 Jul 2004 09:25:03 +1000 Lines: 84 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: 203.10.46.175 Message-ID: <40ec8643@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089242691 203.10.46.175 (7 Jul 2004 16:24:51 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail