Solved

shutdown/reboot win nt4

Posted on 2000-02-28
4
139 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 100 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

622 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