mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 05:43:08 +00:00
Create a branch for header work.
svn path=/branches/header-work/; revision=45691
This commit is contained in:
parent
14fe274b1c
commit
9ea495ba33
19538 changed files with 0 additions and 1063950 deletions
14
base/applications/shutdown/lang/bg-BG.rc
Normal file
14
base/applications/shutdown/lang/bg-BG.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_BULGARIAN, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Употреба: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Без ключове или -?\tПоказва това съобщение\n\
|
||||
-l\t\t\tИзход\n\
|
||||
-s\t\t\tИзключване на компютъра\n\
|
||||
-r\t\t\tИзключване и презапускане на компютъра\n\
|
||||
-f\t\t\tНасилване на работещите приложения да се затворят без предупреждение\n\
|
||||
\t\t\tАко не сте задали други ключове, тази възможност\n\
|
||||
\t\t\tще доведе до изход от потребителя"
|
||||
END
|
19
base/applications/shutdown/lang/de-DE.rc
Normal file
19
base/applications/shutdown/lang/de-DE.rc
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* German language file by Colin Finck <2007-07-18>
|
||||
*/
|
||||
|
||||
LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Syntax: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Keine Argumente\tDiese Meldung anzeigen\n\
|
||||
-?\t\t\tDiese Meldung anzeigen\n\
|
||||
-l\t\t\tBenutzer abmelden\n\
|
||||
-s\t\t\tComputer herunterfahren\n\
|
||||
-r\t\t\tComputer herunterfahren und neu starten\n\
|
||||
-f\t\t\tLaufende Anwendungen ohne Warnung schließen\n\
|
||||
\t\t\tWenn Sie keine weiteren Parameter angegeben haben,\n\
|
||||
\t\t\tmeldet Sie diese Option auch ab"
|
||||
END
|
14
base/applications/shutdown/lang/el-GR.rc
Normal file
14
base/applications/shutdown/lang/el-GR.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_GREEK, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Χρήση: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Κανένα όρισμα ή -?\tΕμφάνιση αυτού του μηνύματος\n\
|
||||
-l\t\t\tΑποσύνδεση\n\
|
||||
-s\t\t\tΤερματισμός του υπολογιστή\n\
|
||||
-r\t\t\tΤερματισμός και επανεκκίνηση του υπολογιστή\n\
|
||||
-f\t\t\tΕξαναγκάζει τις τρέχουσες εφαρμογές να κλείσουν χωρίς προειδοποίηση\n\
|
||||
\t\t\tΑν δε δηλώσατε κάποια άλλη παράμετρο, αυτή η επιλογή\n\
|
||||
\t\t\tθα κάνει την αποσύνδεση"
|
||||
END
|
14
base/applications/shutdown/lang/en-US.rc
Normal file
14
base/applications/shutdown/lang/en-US.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Usage: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
No arguments or -?\tDisplay this message\n\
|
||||
-l\t\t\tLog off\n\
|
||||
-s\t\t\tShutdown the computer\n\
|
||||
-r\t\t\tShutdown and restart the computer\n\
|
||||
-f\t\t\tForces running applications to close without warnings\n\
|
||||
\t\t\tIf you did not specify any other parameter, this option\n\
|
||||
\t\t\twill also log off"
|
||||
END
|
14
base/applications/shutdown/lang/fr-FR.rc
Normal file
14
base/applications/shutdown/lang/fr-FR.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Utilisation: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Aucun argument ou -?\tAffichent ce message\n\
|
||||
-l\t\t\tSe déconnecter\n\
|
||||
-s\t\t\tÉteindre l'ordinateur\n\
|
||||
-r\t\t\tÉteindre et redémarrer l'ordinateur\n\
|
||||
-f\t\t\tForce les applications en cours de fonctionnement à se fermer sans avertissements\n\
|
||||
\t\t\tSi vous ne spécifiez aucun autre paramètre, cette option\n\
|
||||
\t\t\tprovoquera aussi une déconnexion"
|
||||
END
|
14
base/applications/shutdown/lang/it-IT.rc
Normal file
14
base/applications/shutdown/lang/it-IT.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_ITALIAN, SUBLANG_NEUTRAL
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Uso: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Senza parametri o con -?\tvisualizza questo messaggio\n\
|
||||
-l\t\t\tChiude la sessione\n\
|
||||
-s\t\t\tSpegnimento del computer\n\
|
||||
-r\t\t\tRiavvio del computer\n\
|
||||
-f\t\t\tArresta le applicazioni senza nessun avviso\n\
|
||||
\t\t\tSe non viene specificato nessun altro parametro verrà\n\
|
||||
\t\t\tchiusa la sessione"
|
||||
END
|
14
base/applications/shutdown/lang/ja-JP.rc
Normal file
14
base/applications/shutdown/lang/ja-JP.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "使用法: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
引数なしもしくは -?\tこのメッセージを表\示します\n\
|
||||
-l\t\t\tログオフ\n\
|
||||
-s\t\t\tコンピュータをシャットダウンします\n\
|
||||
-r\t\t\tコンピュータをシャットダウンして再起動します\n\
|
||||
-f\t\t\t実行中のアプリケーションを警告なしに閉じます\n\
|
||||
\t\t\t他のパラメータを指定しない場合、ログオフn\n\
|
||||
\t\t\tします"
|
||||
END
|
17
base/applications/shutdown/lang/ko-KR.rc
Normal file
17
base/applications/shutdown/lang/ko-KR.rc
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Korean translation by manatails007(www.manatails007.org)
|
||||
*/
|
||||
LANGUAGE LANG_KOREAN, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "사용법: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
지시문 없음 -?\t이 메세지 표시\n\
|
||||
-l\t\t\t로그 오프\n\
|
||||
-s\t\t\t컴퓨터 끄기\n\
|
||||
-r\t\t\t컴퓨터 재시작\n\
|
||||
-f\t\t\t프로세스 강제종료\n\
|
||||
\t\t\t아무 파라미터도 입력하지 않으시면,\n\
|
||||
\t\t\t로그오프 될 것입니다"
|
||||
END
|
16
base/applications/shutdown/lang/lt-LT.rc
Normal file
16
base/applications/shutdown/lang/lt-LT.rc
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* Translation by Vytis "CMan" Girdþijauskas (cman@cman.us) */
|
||||
|
||||
LANGUAGE LANG_LITHUANIAN, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Naudojimas: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Be parametrø arba -?\tParodyti ðá praneðimà\n\
|
||||
-l\t\t\tAtsijungti\n\
|
||||
-s\t\t\tIðjungti kompiuterá\n\
|
||||
-r\t\t\tPerkrauti kompiuterá\n\
|
||||
-f\t\t\tPriverstinai uþverti visas paleistas programas\n\
|
||||
\t\t\tJeigu nenurodyti jokie kiti parametrai, taip pat\n\
|
||||
\t\t\tbus ávykdytas atsijungimas"
|
||||
END
|
14
base/applications/shutdown/lang/nl-NL.rc
Normal file
14
base/applications/shutdown/lang/nl-NL.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_DUTCH, SUBLANG_NEUTRAL
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Usage: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
No arguments or -?\tDisplay this message\n\
|
||||
-l\t\t\tLog off\n\
|
||||
-s\t\t\tDe computer afsluiten\n\
|
||||
-r\t\t\tOpnieuw opstarten\n\
|
||||
-f\t\t\tProgrammas zonder waarschuwing afsluiten\n\
|
||||
\t\t\tAls u geen andere optie hebt geselecteerd, dan zal deze functie\n\
|
||||
\t\t\tu ook doen afmelden"
|
||||
END
|
14
base/applications/shutdown/lang/no-NO.rc
Normal file
14
base/applications/shutdown/lang/no-NO.rc
Normal file
|
@ -0,0 +1,14 @@
|
|||
LANGUAGE LANG_NORWEGIAN, SUBLANG_NEUTRAL
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Bruk: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Ingen parametere eller -?\tVis denne meldingen\n\
|
||||
-l\t\t\tLogg av\n\
|
||||
-s\t\t\tSkru av maskinen\n\
|
||||
-r\t\t\tSkru av og start maskinen på nytt\n\
|
||||
-f\t\t\tTvinger alle programmer til å avsluttes, og dersom\n\
|
||||
\t\t\tdet ikke er spesifisert andre parametere vil\n\
|
||||
\t\t\tbrukeren også logges ut."
|
||||
END
|
21
base/applications/shutdown/lang/pl-PL.rc
Normal file
21
base/applications/shutdown/lang/pl-PL.rc
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* translated by Caemyr - Olaf Siejka (Dec,2007)
|
||||
* Use ReactOS forum PM or IRC to contact me
|
||||
* http://www.reactos.org
|
||||
* IRC: irc.freenode.net #reactos-pl;
|
||||
*/
|
||||
|
||||
LANGUAGE LANG_POLISH, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Składnia: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Bez parametrów albo z -?\tWyświetla niniejszą pomoc\n\
|
||||
-l\t\t\tWylogowanie\n\
|
||||
-s\t\t\tWyłączenie komputera\n\
|
||||
-r\t\t\tRestart komputera\n\
|
||||
-f\t\t\tZamknięcie wszystkich działających aplikacji, bez ostrzeżenia\n\
|
||||
\t\t\tBez podania innego parametru, ta opcja domyślnie wyloguje \n\
|
||||
\t\t\tobecnego użytkownika"
|
||||
END
|
17
base/applications/shutdown/lang/ru-RU.rc
Normal file
17
base/applications/shutdown/lang/ru-RU.rc
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Russian language resource file (Dmitry Chapyshev, 2007-07-19)
|
||||
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Использование: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Без аргументов или -?\tОтображение этого сообщения\n\
|
||||
-l\t\t\tЗавершение сеанса\n\
|
||||
-s\t\t\tВыключение этого компьютера\n\
|
||||
-r\t\t\tПерезагрузка этого компьютера\n\
|
||||
-f\t\t\tИгнорирование запущенных программ и завершение их без\n\
|
||||
\t\t\tпредупреждения\n\
|
||||
\t\t\tЕсли вы не указали другие параметры, то эта опция\n\
|
||||
\t\t\tприведет к завершению сеанса."
|
||||
END
|
23
base/applications/shutdown/lang/sk-SK.rc
Normal file
23
base/applications/shutdown/lang/sk-SK.rc
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Shutdown Utility
|
||||
* FILE: base/applications/shutdown/lang/sk-SK.rc
|
||||
* PURPOSE: Slovak Language File for shutdown
|
||||
* TRANSLATOR: Kario (kario@szm.sk)
|
||||
* DATE OF TR: 25-07-2007
|
||||
*/
|
||||
|
||||
LANGUAGE LANG_SLOVAK, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Pou§itie: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
¦iadne argumenty\tZobraz¡ sa t to spr va\n\
|
||||
-?\t\t\tZobraz¡ t£to spr vu\n\
|
||||
-l\t\t\tOdhl si pou§¡vate–a\n\
|
||||
-s\t\t\tVypne poŸ¡taŸ\n\
|
||||
-r\t\t\tReçtartuje poŸ¡taŸ\n\
|
||||
-f\t\t\tDon£ti spusten‚ programy aby sa vypli bez upozornen¡.\n\
|
||||
\t\t\tAk nebol zadanì §iadny inì parameter, tak aj odhl si\n\
|
||||
\t\t\tpou§¡vate–a."
|
||||
END
|
22
base/applications/shutdown/lang/uk-UA.rc
Normal file
22
base/applications/shutdown/lang/uk-UA.rc
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* PROJECT: ReactOS shutdown/logoff utility
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/applications/shutdown/lang/uk-UA.rc
|
||||
* PURPOSE: Ukraianian Language File for shutdown
|
||||
* TRANSLATOR: Artem Reznikov
|
||||
*/
|
||||
|
||||
LANGUAGE LANG_UKRAINIAN, SUBLANG_DEFAULT
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
|
||||
IDS_USAGE, "Âèêîðèñòàííÿ: shutdown [-?] [-l | -s | -r] [-f]\n\n\
|
||||
Áåç àðãóìåíò³â àáî -?\t³äîáðàæåííÿ öüîãî ïîâ³äîìëåííÿ\n\
|
||||
-l\t\t\tÇàâåðøåííÿ ñåàíñó\n\
|
||||
-s\t\t\tÂèìêíåííÿ öüîãî êîìï'þòåðà\n\
|
||||
-r\t\t\tÏåðåçàâàíòàæåííÿ öüîãî êîìï'þòåðà\n\
|
||||
-f\t\t\tÏðèìóñîâå çàêðèòòÿ çàïóùåíèõ äîäàòê³â áåç ïîïåðåäæåíü\n\
|
||||
\t\t\tßêùî âè íå âêàçàëè ³íøèé ïàðàìåòð, òî öÿ îïö³ÿ òàêîæ\n\
|
||||
\t\t\tçàâåðøèòü ñåàíñ"
|
||||
END
|
63
base/applications/shutdown/misc.c
Normal file
63
base/applications/shutdown/misc.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include "precomp.h"
|
||||
|
||||
static INT
|
||||
LengthOfStrResource(IN HINSTANCE hInst,
|
||||
IN UINT uID)
|
||||
{
|
||||
HRSRC hrSrc;
|
||||
HGLOBAL hRes;
|
||||
LPWSTR lpName, lpStr;
|
||||
|
||||
if (hInst == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* There are always blocks of 16 strings */
|
||||
lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
|
||||
|
||||
/* Find the string table block */
|
||||
if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
|
||||
(hRes = LoadResource(hInst, hrSrc)) &&
|
||||
(lpStr = (WCHAR*) LockResource(hRes)))
|
||||
{
|
||||
UINT x;
|
||||
|
||||
/* Find the string we're looking for */
|
||||
uID &= 0xF; /* position in the block, same as % 16 */
|
||||
for (x = 0; x < uID; x++)
|
||||
{
|
||||
lpStr += (*lpStr) + 1;
|
||||
}
|
||||
|
||||
/* Found the string */
|
||||
return (int)(*lpStr);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
INT
|
||||
AllocAndLoadString(OUT LPTSTR *lpTarget,
|
||||
IN HINSTANCE hInst,
|
||||
IN UINT uID)
|
||||
{
|
||||
INT ln;
|
||||
|
||||
ln = LengthOfStrResource(hInst,
|
||||
uID);
|
||||
if (ln++ > 0)
|
||||
{
|
||||
(*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED,
|
||||
ln * sizeof(TCHAR));
|
||||
if ((*lpTarget) != NULL)
|
||||
{
|
||||
INT Ret;
|
||||
if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
|
||||
{
|
||||
LocalFree((HLOCAL)(*lpTarget));
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
16
base/applications/shutdown/precomp.h
Normal file
16
base/applications/shutdown/precomp.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef __SHUTDOWN_PRECOMP_H
|
||||
#define __SHUTDOWN_PRECOMP_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <reason.h> //shutdown codes
|
||||
#include "resource.h"
|
||||
|
||||
// misc.c
|
||||
INT AllocAndLoadString(OUT LPTSTR *lpTarget,
|
||||
IN HINSTANCE hInst,
|
||||
IN UINT uID);
|
||||
|
||||
#endif
|
1
base/applications/shutdown/resource.h
Normal file
1
base/applications/shutdown/resource.h
Normal file
|
@ -0,0 +1 @@
|
|||
#define IDS_USAGE 1000
|
19
base/applications/shutdown/rsrc.rc
Normal file
19
base/applications/shutdown/rsrc.rc
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <windows.h>
|
||||
#include "resource.h"
|
||||
|
||||
#include "lang/bg-BG.rc"
|
||||
#include "lang/de-DE.rc"
|
||||
#include "lang/el-GR.rc"
|
||||
#include "lang/en-US.rc"
|
||||
#include "lang/fr-FR.rc"
|
||||
#include "lang/it-IT.rc"
|
||||
#include "lang/ja-JP.rc"
|
||||
#include "lang/ko-KR.rc"
|
||||
#include "lang/lt-LT.rc"
|
||||
#include "lang/nl-NL.rc"
|
||||
#include "lang/no-NO.rc"
|
||||
#include "lang/pl-PL.rc"
|
||||
#include "lang/ru-RU.rc"
|
||||
#include "lang/sk-SK.rc"
|
||||
#include "lang/uk-UA.rc"
|
||||
|
230
base/applications/shutdown/shutdown.c
Normal file
230
base/applications/shutdown/shutdown.c
Normal file
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS shutdown/logoff utility
|
||||
* FILE: base/application/shutdown/shutdown.c
|
||||
* PURPOSE: Initiate logoff, shutdown or reboot of the system
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
// Print information about which commandline arguments the program accepts.
|
||||
static void PrintUsage() {
|
||||
LPTSTR lpUsage = NULL;
|
||||
DWORD errLength; // error message length
|
||||
LPTSTR resMsg; // for error message in OEM symbols
|
||||
|
||||
if( AllocAndLoadString( &lpUsage,
|
||||
GetModuleHandle(NULL),
|
||||
IDS_USAGE ) )
|
||||
{
|
||||
errLength = strlen(lpUsage) + 1;
|
||||
resMsg = (LPTSTR)LocalAlloc(LPTR, errLength * sizeof(TCHAR));
|
||||
CharToOemBuff(lpUsage, resMsg, errLength);
|
||||
|
||||
_putts( resMsg );
|
||||
|
||||
LocalFree(lpUsage);
|
||||
LocalFree(resMsg);
|
||||
}
|
||||
}
|
||||
|
||||
struct CommandLineOptions {
|
||||
BOOL abort; // Not used yet
|
||||
BOOL force;
|
||||
BOOL logoff;
|
||||
BOOL restart;
|
||||
BOOL shutdown;
|
||||
};
|
||||
|
||||
struct ExitOptions {
|
||||
// This flag is used to distinguish between a user-initiated LOGOFF (which has value 0)
|
||||
// and an underdetermined situation because user didn't give an argument to start Exit.
|
||||
BOOL shouldExit;
|
||||
// flags is the type of shutdown to do - EWX_LOGOFF, EWX_REBOOT, EWX_POWEROFF, etc..
|
||||
UINT flags;
|
||||
// reason is the System Shutdown Reason code. F.instance SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED.
|
||||
DWORD reason;
|
||||
};
|
||||
|
||||
// Takes the commandline arguments, and creates a struct which matches the arguments supplied.
|
||||
static struct CommandLineOptions ParseArguments(int argc, TCHAR *argv[])
|
||||
{
|
||||
struct CommandLineOptions opts;
|
||||
int i;
|
||||
|
||||
// Reset all flags in struct
|
||||
opts.abort = FALSE;
|
||||
opts.force = FALSE;
|
||||
opts.logoff = FALSE;
|
||||
opts.restart = FALSE;
|
||||
opts.shutdown = FALSE;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] == '-' || argv[i][0] == '/')
|
||||
{
|
||||
switch(argv[i][1]) {
|
||||
case '?':
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
case 'f':
|
||||
case 'F':
|
||||
opts.force = TRUE;
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
opts.logoff = TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
opts.restart = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
opts.shutdown = TRUE;
|
||||
break;
|
||||
default:
|
||||
// Unknown arguments will exit program.
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
// Converts the commandline arguments to flags used to shutdown computer
|
||||
static struct ExitOptions ParseCommandLineOptionsToExitOptions(struct CommandLineOptions opts)
|
||||
{
|
||||
struct ExitOptions exitOpts;
|
||||
exitOpts.shouldExit = TRUE;
|
||||
|
||||
// Sets ONE of the exit type flags
|
||||
if (opts.logoff)
|
||||
exitOpts.flags = EWX_LOGOFF;
|
||||
else if (opts.restart)
|
||||
exitOpts.flags = EWX_REBOOT;
|
||||
else if(opts.shutdown)
|
||||
exitOpts.flags = EWX_POWEROFF;
|
||||
else
|
||||
{
|
||||
exitOpts.flags = 0;
|
||||
exitOpts.shouldExit = FALSE;
|
||||
}
|
||||
|
||||
// Sets additional flags
|
||||
if (opts.force)
|
||||
{
|
||||
exitOpts.flags = exitOpts.flags | EWX_FORCE;
|
||||
|
||||
// This makes sure that we log off, also if there is only the "-f" option specified.
|
||||
// The Windows shutdown utility does it the same way.
|
||||
exitOpts.shouldExit = TRUE;
|
||||
}
|
||||
|
||||
// Reason for shutdown
|
||||
// Hardcoded to "Other (Planned)"
|
||||
exitOpts.reason = SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED;
|
||||
|
||||
return exitOpts;
|
||||
}
|
||||
|
||||
// Writes the last error as both text and error code to the console.
|
||||
void DisplayLastError()
|
||||
{
|
||||
int errorCode = GetLastError();
|
||||
LPTSTR lpMsgBuf = NULL;
|
||||
DWORD errLength; // error message length
|
||||
LPTSTR resMsg; // for error message in OEM symbols
|
||||
|
||||
// Display the error message to the user
|
||||
errLength = FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
errorCode,
|
||||
LANG_USER_DEFAULT,
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
0,
|
||||
NULL) + 1;
|
||||
|
||||
resMsg = (LPTSTR)LocalAlloc(LPTR, errLength * sizeof(TCHAR));
|
||||
CharToOemBuff(lpMsgBuf, resMsg, errLength);
|
||||
|
||||
_ftprintf(stderr, resMsg);
|
||||
_ftprintf(stderr, _T("Error code: %d\n"), errorCode);
|
||||
|
||||
LocalFree(lpMsgBuf);
|
||||
LocalFree(resMsg);
|
||||
}
|
||||
|
||||
void EnableShutdownPrivileges()
|
||||
{
|
||||
HANDLE token;
|
||||
TOKEN_PRIVILEGES privs;
|
||||
|
||||
// Check to see if the choosen action is allowed by the user. Everyone can call LogOff, but only privilieged users can shutdown/restart etc.
|
||||
if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))
|
||||
{
|
||||
DisplayLastError();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Get LUID (Locally Unique Identifier) for the privilege we need
|
||||
if (!LookupPrivilegeValue(
|
||||
NULL, // system - NULL is localsystem
|
||||
SE_SHUTDOWN_NAME, // name of the privilege
|
||||
&privs.Privileges[0].Luid) // output
|
||||
)
|
||||
{
|
||||
DisplayLastError();
|
||||
exit(1);
|
||||
}
|
||||
// and give our current process (i.e. shutdown.exe) the privilege to shutdown the machine.
|
||||
privs.PrivilegeCount = 1;
|
||||
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
if (AdjustTokenPrivileges(
|
||||
token,
|
||||
FALSE,
|
||||
&privs,
|
||||
0,
|
||||
(PTOKEN_PRIVILEGES)NULL, // previous state. Set to NULL, we don't care about previous state.
|
||||
NULL
|
||||
) == 0) // return value 0 means failure
|
||||
{
|
||||
DisplayLastError();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Main entry for program
|
||||
int _tmain(int argc, TCHAR *argv[])
|
||||
{
|
||||
struct CommandLineOptions opts;
|
||||
struct ExitOptions exitOpts;
|
||||
|
||||
if (argc == 1) // i.e. no commandline arguments given
|
||||
{
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
opts = ParseArguments(argc, argv);
|
||||
exitOpts = ParseCommandLineOptionsToExitOptions(opts);
|
||||
|
||||
// Perform the shutdown/restart etc. action
|
||||
if (exitOpts.shouldExit)
|
||||
{
|
||||
EnableShutdownPrivileges();
|
||||
|
||||
if (!ExitWindowsEx(exitOpts.flags, exitOpts.reason))
|
||||
{
|
||||
DisplayLastError();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EOF
|
11
base/applications/shutdown/shutdown.rbuild
Normal file
11
base/applications/shutdown/shutdown.rbuild
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
|
||||
<module name="shutdown" type="win32cui" installbase="system32" installname="shutdown.exe">
|
||||
<include base="shutdown">.</include>
|
||||
<library>advapi32</library>
|
||||
<library>user32</library>
|
||||
<file>misc.c</file>
|
||||
<file>shutdown.c</file>
|
||||
<file>shutdown.rc</file>
|
||||
<pch>precomp.h</pch>
|
||||
</module>
|
9
base/applications/shutdown/shutdown.rc
Normal file
9
base/applications/shutdown/shutdown.rc
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <windows.h>
|
||||
#include "resource.h"
|
||||
|
||||
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Shutdown Utility\0"
|
||||
#define REACTOS_STR_INTERNAL_NAME "shutdown\0"
|
||||
#define REACTOS_STR_ORIGINAL_FILENAME "shutdown.exe\0"
|
||||
#include <reactos/version.rc>
|
||||
|
||||
#include "rsrc.rc"
|
Loading…
Add table
Add a link
Reference in a new issue