{"id":327,"date":"2008-05-17T21:09:09","date_gmt":"2008-05-17T21:09:09","guid":{"rendered":"http:\/\/6teen.ru\/?p=38"},"modified":"2008-05-17T21:09:09","modified_gmt":"2008-05-17T21:09:09","slug":"6994","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=327","title":{"rendered":"shutdown \/ reboot \/ logoff Windows 9x\/NT\/Me\/2000\/XP?"},"content":{"rendered":"<p>shutdown \/ reboot \/ logoff Windows 9x\/NT\/Me\/2000\/XP?<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>shutdown \/ reboot \/ logoff Windows 9x\/NT\/Me\/2000\/XP?\n{1.}\n\nfunction myexitwindows(rebootparam: longword): boolean;\nvar\nttokenhd: thandle;\nttokenpvg: ttokenprivileges;\ncbtpprevious: dword;\nrttokenpvg: ttokenprivileges;\npcbtppreviousrequired: dword;\ntpresult: boolean;\nconst\nse_shutdown_name = 'seshutdownprivilege';\nbegin\nif win32platform = ver_platform_win32_nt then\nbegin\ntpresult := openprocesstoken(getcurrentprocess(),\ntoken_adjust_privileges or token_query,\nttokenhd);\nif tpresult then\nbegin\ntpresult := lookupprivilegevalue(nil,\nse_shutdown_name,\nttokenpvg.privileges[0].luid);\nttokenpvg.privilegecount := 1;\nttokenpvg.privileges[0].attributes := se_privilege_enabled;\ncbtpprevious := sizeof(rttokenpvg);\npcbtppreviousrequired := 0;\nif tpresult then\nwindows.adjusttokenprivileges(ttokenhd,\nfalse,\nttokenpvg,\ncbtpprevious,\nrttokenpvg,\npcbtppreviousrequired);\nend;\nend;\nresult := exitwindowsex(rebootparam, 0);\nend;\n\n\/\/ example to shutdown windows:\n\nprocedure tform1.button1click(sender: tobject);\nbegin\nmyexitwindows(ewx_poweroff or ewx_force);\nend;\n\n\/\/ example to reboot windows:\n\nprocedure tform1.button1click(sender: tobject);\nbegin\nmyexitwindows(ewx_reboot or ewx_force);\nend;\n\n\n\/\/ parameters for myexitwindows()\n\n\n{************************************************************************}\n\n{2. console shutdown demo}\n\nprogram shutdown;\n{$apptype console}\n\nuses\nsysutils,\nwindows;\n\n\/\/ shutdown program\n\/\/ (c) 2000 neuralabyss software\n\/\/ www.neuralabyss.com\n\nvar\nlogoff: boolean = false;\nreboot: boolean = false;\nwarn: boolean = false;\ndownquick: boolean = false;\ncancelshutdown: boolean = false;\npoweroff: boolean = false;\ntimedelay: integer = 0;\n\nfunction hasparam(opt: char): boolean;\nvar\nx: integer;\nbegin\nresult := false;\nfor x := 1 to paramcount do\nif (paramstr(x) = '-' + opt) or (paramstr(x) = '\/' + opt) then result := true;\nend;\n\nfunction geterrorstring: string;\nvar\nlz: cardinal;\nerr: array[0..512] of char;\nbegin\nlz := getlasterror;\nformatmessage(format_message_from_system, nil, lz, 0, @err, 512, nil);\nresult := string(err);\nend;\n\nprocedure doshutdown;\nvar\nrl, flgs: cardinal;\nhtoken: cardinal;\ntkp: token_privileges;\nbegin\nflgs := 0;\nif downquick then flgs := flgs or ewx_force;\nif not reboot then flgs := flgs or ewx_shutdown;\nif reboot then flgs := flgs or ewx_reboot;\nif poweroff and (not reboot) then flgs := flgs or ewx_poweroff;\nif logoff then flgs := (flgs and (not (ewx_reboot or ewx_shutdown or ewx_poweroff))) or\newx_logoff;\nif win32platform = ver_platform_win32_nt then\nbegin\nif not openprocesstoken(getcurrentprocess, token_adjust_privileges or token_query,\nhtoken) then\nwriteln('cannot open process token. [' + geterrorstring + ']')\nelse\nbegin\nif lookupprivilegevalue(nil, 'seshutdownprivilege', tkp.privileges[0].luid) then\nbegin\ntkp.privileges[0].attributes := se_privilege_enabled;\ntkp.privilegecount := 1;\nadjusttokenprivileges(htoken, false, tkp, 0, nil, rl);\nif getlasterror <> error_success then\nwriteln('error adjusting process privileges.');\nend\nelse\nwriteln('cannot find privilege value. [' + geterrorstring + ']');\nend;\n{ if cancelshutdown then\nif abortsystemshutdown(nil) = false then\nwriteln(\\'cannot abort. [\\' + geterrorstring + \\']\\')\nelse\nwriteln(\\'cancelled.\\')\nelse\nbegin\nif initiatesystemshutdown(nil, nil, timedelay, downquick, reboot) = false then\nwriteln(\\'cannot go down. [\\' + geterrorstring + \\']\\')\nelse\nwriteln(\\'shutting down!\\');\nend;\n}\nend;\n\/\/ else begin\nexitwindowsex(flgs, 0);\n\/\/ end;\nend;\n\nbegin\nwriteln('shutdown v0.3 for win32 (similar to the linux version)');\nwriteln('(c) 2000 neuralabyss software. all rights reserved.');\nif hasparam('?') or (paramcount = 0) then\nbegin\nwriteln('usage: shutdown [-akrhfnc] [-t secs]');\nwriteln(' -k: don''t really shutdown, only warn.');\nwriteln(' -r: reboot after shutdown.');\nwriteln(' -h: halt after shutdown.');\nwriteln(' -p: power off after shutdown');\nwriteln(' -l: log off only');\nwriteln(' -n: kill apps that don''t want to die.');\nwriteln(' -c: cancel a running shutdown.');\nend\nelse\nbegin\nif hasparam('k') then warn := true;\nif hasparam('r') then reboot := true;\nif hasparam('h') and reboot then\nbegin\nwriteln('error: cannot specify -r and -h parameters together!');\nexit;\nend;\nif hasparam('h') then reboot := false;\nif hasparam('n') then downquick := true;\nif hasparam('c') then cancelshutdown := true;\nif hasparam('p') then poweroff := true;\nif hasparam('l') then logoff := true;\ndoshutdown;\nend;\nend.\n\n\n\n\n\n\/\/ parameters for myexitwindows()\n\n\newx_logoff\n\nshuts down all processes running in the security context of the process that called the\nexitwindowsex function. then it logs the user off.\n\nalle prozesse des benutzers werden beendet, danach wird der benutzer abgemeldet.\n\newx_poweroff\n\nshuts down the system and turns off the power.\nthe system must support the power-off feature.\nwindows nt\/2000\/xp:\nthe calling process must have the se_shutdown_name privilege.\n\nf\u0434hrt windows herunter und setzt den computer in den standby-modus,\nsofern von der hardware unterst\u044ctzt.\n\newx_reboot\n\nshuts down the system and then restarts the system.\nwindows nt\/2000\/xp: the calling process must have the se_shutdown_name privilege.\n\nf\u0434hrt windows herunter und startet es neu.\n\newx_shutdown\n\nshuts down the system to a point at which it is safe to turn off the power.\nall file buffers have been flushed to disk, and all running processes have stopped.\nif the system supports the power-off feature, the power is also turned off.\nwindows nt\/2000\/xp: the calling process must have the se_shutdown_name privilege.\n\nf\u0434hrt windows herunter.\n\n\newx_force\n\nforces processes to terminate. when this flag is set,\nthe system does not send the wm_queryendsession and wm_endsession messages.\nthis can cause the applications to lose data.\ntherefore, you should only use this flag in an emergency.\n\ndie aktiven prozesse werden zwangsweise und ohne r\u044cckfrage beendet.\n\newx_forceifhung\n\nwindows 2000\/xp: forces processes to terminate if they do not respond to the\nwm_queryendsession or wm_endsession message. this flag is ignored if ewx_force is used.\n\nwindows 2000\/xp: die aktiven prozesse werden aufgefordert, sich selbst zu beenden und\nm\u044cssen dies best\u0434tigen. reagieren sie nicht, werden sie zwangsweise beendet.\n\nautor: neuralabyss software\nhomepage: http:\/\/www.neuralabyss.com\n\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: http:\/\/www.swissdelphicenter.ch\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>shutdown \/ reboot \/ logoff Windows 9x\/NT\/Me\/2000\/XP?<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[431,439],"tags":[483,541,126,142,603],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/327"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}