Solved

shutdown/reboot win nt4

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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