Solved

shutdown a win 2000 system

Posted on 2002-05-26
5
177 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 183
Reconfigure Delphi Install? 2 75
How to convert memory stream to PDF file 6 219
Wincontrol not (correctly) drawn 15 55
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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