Article View: nl.comp.programmeren
Article #860Re: Power-off
From: Peter
Date: Tue, 06 Jul 1999 00:00
Date: Tue, 06 Jul 1999 00:00
204 lines
8646 bytes
8646 bytes
--------------3F62B3AD18D4A5D18B6030D4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hier is een voorbeeldje uit de Win32 programmer's reference
ik hoop dat je er wat aan hebt.
Peter
----------------------------------------------------------------------------------
You can use the ExitWindowsEx (zie beneden voor de beschrijving)
function to shut down the system. Shutting down flushes file buffers to
disk and brings the system to a condition in which it is safe to turn
off the computer.
Windows NT: The following example enables the SE_SHUTDOWN_NAME privilege
and then shuts down the system.
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
========================================================
ExitWindowsEx function help
The ExitWindowsEx function either logs off, shuts down, or shuts down
and restarts the system.
BOOL ExitWindowsEx(
UINT uFlags, // shutdown operation
DWORD dwReserved // reserved
);
Parameters
uFlags
Specifies the type of shutdown. This parameter must be some combination
of the following values:
Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, Windows
does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the
applications currently running in the system. This can cause the
applications to lose data. Therefore, you should only use this flag in
an emergency.
EWX_LOGOFF Shuts down all processes running in the security context of
the process that called the ExitWindowsEx function. Then it logs the
user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system
must support the power-off feature.Windows NT: The calling process must
have the SE_SHUTDOWN_NAME privilege. For more information, see the
following Remarks section. Windows 95: Security privileges are not
supported or required.
EWX_REBOOT Shuts down the system and then restarts the system. Windows
NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For
more information, see the following Remarks section. Windows 95:
Security privileges are not supported or required.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to
turn off the power. All file buffers have been flushed to disk, and all
running processes have stopped. Windows NT: The calling process must
have the SE_SHUTDOWN_NAME privilege. For more information, see the
following Remarks section. Windows 95: Security privileges are not
supported or required.
dwReserved
Reserved; this parameter is ignored.
------------------------------------------------------------------------------------
Arian Haeser wrote:
> hi all :))
>
> Weet iemand de code om een ATX-systeem uit te schakelen??
>
> Arian Haeser
--------------3F62B3AD18D4A5D18B6030D4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hier is een voorbeeldje uit de Win32 programmer's reference
<br>ik hoop dat je er wat aan hebt.
<p>Peter
<br>----------------------------------------------------------------------------------
<br>You can use the <b>ExitWindowsEx</b> (zie beneden voor de beschrijving)
function to shut down the system. Shutting down flushes file buffers to
disk and brings the system to a condition in which it is safe to turn off
the computer.
<p>Windows NT: The following example enables the SE_SHUTDOWN_NAME privilege
and then shuts down the system.
<p>HANDLE hToken;
<br>TOKEN_PRIVILEGES tkp;
<br>
<br>// Get a token for this process.
<br>
<br>if (!OpenProcessToken(GetCurrentProcess(),
<br> TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY, &hToken))
<br> error("OpenProcessToken");
<br>
<br>// Get the LUID for the shutdown privilege.
<br>
<br>LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
<br> &tkp.Privileges[0].Luid);
<br>
<br>tkp.PrivilegeCount = 1; // one privilege to set
<br>tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
<br>
<br>// Get the shutdown privilege for this process.
<p>
<br>AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
<br> (PTOKEN_PRIVILEGES)NULL,
0);
<br>
<br>// Cannot test the return value of AdjustTokenPrivileges.
<br>
<br>if (GetLastError() != ERROR_SUCCESS)
<br> error("AdjustTokenPrivileges");
<br>
<br>// Shut down the system and force all applications to close.
<br>
<br>if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
<br> error("ExitWindowsEx");
<br>========================================================
<br><b>ExitWindowsEx function help</b>
<p>The ExitWindowsEx function either logs off, shuts down, or shuts down
and restarts the system.
<p>BOOL ExitWindowsEx(
<p> UINT uFlags, // shutdown operation
<br> DWORD dwReserved // reserved
<br> );
<br>
<p>Parameters
<p>uFlags
<p>Specifies the type of shutdown. This parameter must be some combination
of the following values:
<p>Value Meaning
<br>EWX_FORCE Forces processes to terminate. When this flag is set, Windows
does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the
applications currently running in the system. This can cause the applications
to lose data. Therefore, you should only use this flag in an emergency.
<br>EWX_LOGOFF Shuts down all processes running in the security context
of the process that called the ExitWindowsEx function. Then it logs the
user off.
<br>EWX_POWEROFF Shuts down the system and turns off the power. The system
must support the power-off feature.Windows NT: The calling process must
have the SE_SHUTDOWN_NAME privilege. For more information, see the following
Remarks section. Windows 95: Security privileges are not supported or required.
<br>EWX_REBOOT Shuts down the system and then restarts the system. Windows
NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more
information, see the following Remarks section. Windows 95: Security privileges
are not supported or required.
<br>EWX_SHUTDOWN Shuts down the system to a point at which it is safe to
turn off the power. All file buffers have been flushed to disk, and all
running processes have stopped. Windows NT: The calling process must have
the SE_SHUTDOWN_NAME privilege. For more information, see the following
Remarks section. Windows 95: Security privileges are not supported or required.
<br>
<p>dwReserved
<p>Reserved; this parameter is ignored.
<br>------------------------------------------------------------------------------------
<br>Arian Haeser wrote:
<blockquote TYPE=CITE>hi all :))
<p>Weet iemand de code om een ATX-systeem uit te schakelen??
<p>Arian Haeser</blockquote>
</html>
--------------3F62B3AD18D4A5D18B6030D4--
Technical Details
Message-ID:
<3781408A.86B96B6A@hccnet.nl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7lq5n8$7ub$1@news.hccnet.nl>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107324,d1e8ece806c938ca X-Google-Attributes: gid107324,public X-Google-Thread: 103946,d1e8ece806c938ca X-Google-Attributes: gid103946,public From: Peter <p.v.duijn@hccnet.nl> Subject: Re: Power-off Date: 1999/07/06 Message-ID: <3781408A.86B96B6A@hccnet.nl> X-Deja-AN: 497569217 References: <7lq5n8$7ub$1@news.hccnet.nl> X-Accept-Language: en Content-Type: multipart/alternative; boundary="------------3F62B3AD18D4A5D18B6030D4" X-Complaints-To: usenet@hccnet.nl X-Trace: news.hccnet.nl 931217503 25803 193.173.115.129 (5 Jul 1999 23:31:43 GMT) Organization: Hobby Computer Club News Network Mime-Version: 1.0 NNTP-Posting-Date: 5 Jul 1999 23:31:43 GMT Newsgroups: nl.comp.programmeren,hccnet.programmeren