{1.}
FUNCTION
MyExitWindows
(
RebootParam
:
Longword
):
Boolean
;
VAR
Ttokenhd
:
Thandle
;
TTokenPvg
:
TTokenPrivileges
;
CBTPPREVIOUS
:
DWORD
;
RttokenPvg
:
TTokenPrivileges
;
PCBTPPREVIOUSREQUIRED
:
DWORD
;
TPRESULT
:
Boolean
;
Const
SE_SHUTDOWN_NAME
=
'SESHUTDOWNPRIVILEGE'
;
Begin
IF
Win32Platform
=
VER_PLATFORM_WIN32_NT
THEN
Begin
TPRESULT
: =
OpenProcesstoken
(
GetCurrentProcess
(),
Token_Adjust_Privileges
oral
Token_Query
,
Ttokenhd
);
IF
TPRESULT
THEN
Begin
TPRESULT
: =
LookuppprivileGeValue
(
NIL
,
SE_SHUTDOWN_NAME
,
TTokenPvg
.
PRIVILEGES
[
0
].
LUID
);
TTokenPvg
.
Privilegecount
: =
1
;
TTokenPvg
.
PRIVILEGES
[
0
].
Attributes
: =
SE_PRIVILE_ENABED
;
CBTPPREVIOUS
: =
Sizeof
(
RttokenPvg
);
PCBTPPREVIOUSREQUIRED
: =
0
;
IF
TPRESULT
THEN
Windows
.
AdjustTokenPrivileges
(
Ttokenhd
,
False
,
TTokenPvg
,
CBTPPREVIOUS
,
RttokenPvg
,
PCBTPPREVIOUSREQUIRED
);
end
;
end
;
Result
: =
EXITWINDOWSEX
(
RebootParam
,
0
);
end
;
// Example to Shutdown Windows:
Procedure
TForm1
.
Button1click
(
Sender
:
TOBJECT
);
Begin
MyExitWindows
(
EWX_POWEROFF
oral
EWX_FORCE
);
end
;
// Example to Reboot Windows:
Procedure
TForm1
.
Button1click
(
Sender
:
TOBJECT
);
Begin
MyExitWindows
(
EWX_REBOOT
oral
EWX_FORCE
);
end
;
// parameters for myexitwindows ()
{********************************************************** **********************}
{2. Console Shutdown Demo}
PROGRAM
Shutdown
;
{$ Apptype console}
Uses
Sysutils
,
Windows
;
// Shutdown Program
// (c) 2000 NeuraBys Software
// www.neurabyss.com
VAR
Logoff
:
Boolean
= FALSE
;
Reboot
:
Boolean
=
False
;
Warn
:
Boolean
=
False
;
Downquick
:
Boolean
=
False
;
Cancelshutdown
:
Boolean
=
False
;
Poweroff
:
Boolean
=
False
;
TIMEDELAY
:
Integer
=
0
;
FUNCTION
Hasparam
(
OPT
:
Charr
):
Boolean
;
VAR
x
:
Integer
;
Begin
Result
: =
False
;
for
x
: =
1
TO
PARAMCOUNT
DO
IF
(
Paramstr
(
x
)
=
'-'
OPT
)
oral
(
Paramstr
(
x
)
=
'/'
OPT
)
THEN
Result
: =
True
;
end
;
FUNCTION
GeTerRRORSTRING
:
String
;
VAR
LZ
:
Cardinal
;
Err
:
array
[
0..512
]
Of
Charr
;
Begin
LZ
: =
GetLastError
;
FormatMessage
(
FORMAT_MESSAGE_FROM_SYSTEM
,
NIL
,
LZ
,
0
,
@
Err
,
512
,
NIL
);
Result
: =
String
(
Err
);
end
;
Procedure
Doshutdown
;
VAR
RL
,
FLGS
:
Cardinal
;
Htoken
:
Cardinal
;
TKP
:
Token_Privileges
;
Begin
FLGS
: =
0
;
IF
Downquick
THEN
FLGS
: =
FLGS
oral
EWX_FORCE
;
IF
NOT
Reboot
THEN
FLGS
: =
FLGS
oral
EWX_SHUTDOWN
;
IF
Reboot
THEN
FLGS
: =
FLGS
oral
EWX_REBOOT
;
IF
Poweroff
and
(
NOT
Reboot
)
THEN
FLGS
: =
FLGS
oral
EWX_POWEROFF
;
IF
Logoff
THEN
FLGS
: =
(
FLGS
and
(
NOT
(
EWX_REBOOT
oral
EWX_SHUTDOWN
oral
EWX_POWEROFF
)))))))
oral
EWX_LOGOFF
;
IF
Win32Platform
=
VER_PLATFORM_WIN32_NT
THEN
Begin
IF
NOT
OpenProcesstoken
(
GetCurrentProcess
,
Token_Adjust_Privileges
oral
Token_Query
,
Htoken
)
THEN
Writeln
(
'Cannot Open process token. ['
GeTerRRORSTRING
']'
)
Else
Begin
IF
LookuppprivileGeValue
(
NIL
,
'SESHUTDOWNPRIVILEGE'
,
TKP
.
PRIVILEGES [
0
].
LUID
)
THEN
Begin
TKP
.
PRIVILEGES
[
0
].
Attributes
: =
SE_PRIVILE_ENABED
;
TKP
.
Privilegecount
: =
1
;
AdjustTokenPrivileges
(
Htoken
,
False
,
TKP
,
0
,
NIL
,
RL
);
IF
GetLastError
<>
Error_Success
THEN
Writeln
(
'Error Adjusting Process Privileges.'
);
end
Else
Writeln
(
'Cannot Find Privilege Value. ['
GeTerRRORSTRING
']'
);
end
;
{If Cancelshutdown Then
IF Abortsystemshutdown (nil) = false thein
Writeln (/ 'cannot Abort. [/' Geterrorstring / '] /')
Else
Writeln (/ 'candeD./')
Else
Begin
IF Initiatesystemshutdown (Nil, Nil, Timedlay, Downquick, Reboot) = false the
Writeln (/ 'Cannot Go Down. [/' Geterrorstring / '] /')
Else
Writeln (/ 'shutting down! /');
END;
}
end
;
// else Begin
EXITWINDOWSEX
(
FLGS
,
0
);
// end;
end
;
Begin
Writeln
(
'Shutdown v0.3 for Win32 (Similar to the Linux Version)'
);
Writeln
(
'(c) 2000 NEURALABYSS SOFTWARE. All Rights Reserved.'
);
IF
Hasparam
(
'?'
)
oral
(
PARAMCOUNT
=
0
)
THEN
Begin
Writeln
(
'Usage: shutdown [-akrhfnc] [-t secs]'
);
Writeln
(
'-K: Don''''t really shutdown, only warn.
);
Writeln
(
'-R: reboot after shutdown.'
);
Writeln
(
'-H: halt after shutdown.'
);
Writeln
(
'-P: power off after shutdown'
);
Writeln
(
'-L: log off only'
);
Writeln
(
'-N: Kill Apps That Don''t Want To Die.');
Writeln
(
'-C: Cancel a Running Shutdown.'
);
end
Else
Begin
IF
Hasparam
(
'K'
)
THEN
Warn
: =
True
;
IF
Hasparam
(
'r'
)
THEN
Reboot
: =
True
;
IF
Hasparam
(
'h'
)
and
Reboot
THEN
Begin
Writeln
(
'Error: Cannot Specify -r and -h parameters together!'
);
Exit
;
end
;
IF
Hasparam
(
'h'
)
THEN
Reboot
: =
False
;
IF
Hasparam
(
'n'
)
THEN
Downquick
: =
True
;
IF
Hasparam
(
'c'
)
THEN
Cancelshutdown
: =
True
;
IF
Hasparam
(
'P'
)
THEN
Poweroff
: =
True
;
IF
Hasparam
(
'L'
)
THEN
Logoff
: =
True
;
Doshutdown
;
end
;
end
.
// parameters for myexitwindows ()
{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.
Alle Prozesse Des Benutzers Werden Bendet, Danach Wird Der Benutzer AbgeMeldet.
EWX_POWEROFF
Shuts down the system and turns off the power.
The System Must Support The Power-Off Feature.
Windows NT / 2000 / XP:
The Calling Process Must Have The SE_SHUTDOWN_NAME PRIVILEGE.
F? HRT Windows Herunter und setzt den COMPUTER in Den Standby-Modus,
Sofern Von der hardware unterstützt.
EWX_REBOOT
Shuts Down The System and The Restarts The System.
Windows NT / 2000 / XP: The Calling Process Must Have The SE_SHUTDOWN_NAME PRIVILEGE.
F? HRT Windows Herunter und Startet Es Neu.
EWX_SHUTDOWN
Shuts Down The System To a point at shich it is safe to turn..
All File Buffers Have Been Flushed to Disk, And All Running Processes Have Stopped.if The System Supports The Power-Off Feature, The Power Is Also Turned Off.
Windows NT / 2000 / XP: The Calling Process Must Have The SE_SHUTDOWN_NAME PRIVILEGE.
F? HRT Windows Herunter.
EWX_FORCE
Forces Processes to Terminate .hen this flag is set,
The System Does Not send The WM_QueryEndSession and WM_ENDSESSION Messages.
This Can Cause The Applications to Lose Data.
Therefore, you should only Use..
Die Aktiven Prozesse Werden ZwangSweise und ohne rückfrage bendet.
EWX_FORCEIFHUNG
Windows 2000 / xp: forces processes to Terminate if They do not respond to the
WM_QUERYENDSESSION or WM_ENDSESSION MESSAGE. THIS flag is ignored if ewx_force is used.
Windows 2000 / XP: Die Aktiven Prozesse Werden AufGefordert, Sich Selbst Zu Beennden Und
Müssen Dies Best? Tigen. Reagieren Sie Nicht, Werden Sie Zwangsweise Beendet.