Solved

shutdown/reboot win nt4

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

yours,
geoka

--------------------------
http://www.line.at
0
Comment
Question by:geoka
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now