Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shutdown/reboot win nt4

Posted on 2000-02-28
4
Medium Priority
?
142 Views
Last Modified: 2010-04-04
how to do ?

yours,
geoka

--------------------------
http://www.line.at
0
Comment
Question by:geoka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 400 total points
ID: 2565984
Use API functions:
1. For ShutDown
   ExitWindowsEx(EWX_SHUTDOWN,0);
2. For Restart
   ExitWindowsEx(EWX_REBOOT,0);
3. For Logoff
   ExitWindowsEx(EWX_LOGOFF,0);

Hope it will help!!! :D

Regards,

Daniel
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2568958
That doesn't work in NT - only works in Windows 9x.

You need this really...

unit ExitWin;
 
interface
 
uses
  Windows;
 
function PlatformNT : boolean;
function ExitWindowsF(uFlags : word) : boolean;

implementation

const
  ANYSIZE_ARRAY    = 1;
  SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';

var
  IsNT : boolean;

function PlatformNT : boolean;
begin
  PlatformNT:=IsNT;
end;

function ExitWindowsNT(uFlags : word) : boolean;
var
  hToken : THandle;
  ptkp, ptkpold : PTokenPrivileges;
  r : dword;
begin
  if OpenProcessToken(GetCurrentProcess,
{$IFDEF DELPHI2}
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken) then
{$ELSE}
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
{$ENDIF}
  begin
    GetMem(ptkp,sizeof(TTOKENPRIVILEGES) +
      (1-ANYSIZE_ARRAY) * sizeof(TLUIDANDATTRIBUTES));
    LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME,
      ptkp^.Privileges[0].Luid);
    ptkp^.PrivilegeCount:=1;
    r:=0;
    ptkpold:=nil;
    if AdjustTokenPrivileges(hToken, false, ptkp^, 0, ptkpold^, r) then       ExitWindowsNT:=ExitWindowsEx(uFlags,0);
  end;
  ExitWindowsNT:=GetLastError=ERROR_SUCCESS;
end;

function ExitWindowsF(uFlags : word) : boolean;
begin
  if IsNT then ExitWindowsF:=ExitWindowsNT(uFlags)
  else ExitWindowsF:=ExitWindowsEx(uFlags,0);
end;
 
procedure CheckOS;
var
  VerInfo : TOSVersionInfo;
begin
  IsNT:=false;
  VerInfo.dwOSVersionInfoSize:=sizeof(VerInfo);
  if (GetVersionEx(VerInfo)) then
    IsNT:=VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT;
end;

begin
  CheckOS;
end.

Save that as a unit, put it in your uses clause, and away you go!  (Works on any windows platform.)

John.
0
 

Author Comment

by:geoka
ID: 2593052
ok. thx for amswers but can't try in next week so you must wait a few days for your points.

yours,
geoka
0
 

Author Comment

by:geoka
ID: 2718742
uuhhh (Edited by Computer101), i wanted to deliver the points to jaymol. may you give the points daniel_c, i'm afraid, but only his comment worked under NT.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question