1 /* $Id: shutdown.c,v 1.2 2000/04/25 23:22:57 ea Exp $
5 * Copyright (C) 1997,1998,1999 Emanuele Aliberti
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this software; see the file COPYING.LIB. If
21 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
22 * Cambridge, MA 02139, USA.
24 * --------------------------------------------------------------------
25 * 1999-05-14 (Emanuele Aliberti)
26 * Released version 1.4.1 under GNU GPL for the ReactOS project.
27 * --------------------------------------------------------------------
37 #ifndef SE_PRIVILEGE_ENABLED
38 #define NTOS_MODE_USER
54 { 'p', EWX_POWEROFF
},
56 { 's', EWX_SHUTDOWN
},
63 DecodeArg( CHAR
* modestr
)
67 if (modestr
[0] != '-' && modestr
[0] != '/')
71 for ( i
= 0; modes
[i
].mode
; ++i
)
73 if (modestr
[1] == modes
[i
].mode
)
86 Shutdown ver. 1.4.1 (compiled on %s, at %s)\n\
87 Copyright (C) 1997-1999 Emanuele Aliberti\n\n\
88 usage: %s [-f] [-l] [-p] [-r] [-s]\n\
89 f (FORCE) processes are unconditionally terminated\n\
90 l (LOGOFF) logs the current user off\n\
91 p (POWEROFF) turns off the power, if possibile\n\
92 r (REBOOT) reboots the system\n\
93 s (SHUTDOWN) shuts down the system to a point at which\n\
94 it is safe to turn off the power\n\n\
95 Any other letter will print this help message.\n";
110 if (mode
== (UINT
) -1)
122 * Get the current process token handle
123 * so we can get shutdown privilege.
125 if (FALSE
== OpenProcessToken(
127 (TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
),
132 L
"while opening the process",
138 * Get the LUID for shutdown privilege.
140 if (FALSE
== LookupPrivilegeValue(
143 & tp
.Privileges
[0].Luid
147 L
"while looking up privileges",
152 tp
.PrivilegeCount
= 1; /* One privilege to seat */
153 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
155 * Get shutdown privilege for this process.
157 if (FALSE
== AdjustTokenPrivileges(
162 (PTOKEN_PRIVILEGES
) NULL
,
167 L
"while adjusting shutdown privilege",
172 /* Now really exit! */
173 if (FALSE
== ExitWindowsEx(mode
, 0))