Solved

shutdown a win 2000 system

Posted on 2002-05-26
5
174 Views
Last Modified: 2010-04-04
hi, is there any way to (by code) shutdown a windows system BUT with a delay? pretty much like shutdown does in Linux

something like i'd like to shutdown the machine in 10 min, so i send 10 min (or the sec.) as a parameter.

it's going to be a quick console application with no timer in it.

thanks!
0
Comment
Question by:urif
5 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 7035203
There is, but I don't have the correct API calls at hand. However, you migh want to look at the freeware console application PSSHUTDOWN from www.sysinternals.com which does EXACTLY that - even allowing you to shutdown remote machines.
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7035341
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7035348
If you don't want to use a timer you could just use the Sleep() function in the SysUtils unit to delay your program for a certain ammount of time. This won't allow your program to process any messages during the execution of the Sleep() function. I sometimes use the below function if i want to process messages during a delayed time period:

procedure Delay(Ms : Longint);
var
  TickCount : LongInt;
begin
  TickCount := GetTickCount;
  while GetTickCount - TickCount < Ms do
    Application.ProcessMessages;
end;
0
 

Author Comment

by:urif
ID: 7036592
what i'm looking for is actually how to implement the call to InitiateSystemShutdown().

i tried the code in swissdelphicenter but it just crashes (on a win2k machine running delphi 5)

any ideas on how to implement this API correctly?

thanks
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 80 total points
ID: 7036645
Well I took some of the code on the swissdelphicenter and reworked it a little bit and works for me on Win2000. This is just raw code so you will need to implement your timing sequence.

procedure TForm1.Button1Click(Sender: TObject);
var
  rl: Cardinal;
  hToken: Cardinal;
  tkp: TOKEN_PRIVILEGES;

begin
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
  hToken) then
    ShowMessage('Cannot open process token.')
  else begin
    if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin
      tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      tkp.PrivilegeCount           := 1;
      AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
      if GetLastError <> ERROR_SUCCESS then
        ShowMessage('Error adjusting process privileges.');
    end
    else
      ShowMessage('Cannot find privilege value.');
  end;

  InitiateSystemShutdown(nil, nil, 0, True, True);

end;


The Crazy One
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 113
Delphi selector screen 2 70
creating threads in delphi 1 82
Tviruailstringtree sort multi columns on header click 1 54
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

15 Experts available now in Live!

Get 1:1 Help Now