?
Solved

Restart Windows

Posted on 2003-03-30
4
Medium Priority
?
341 Views
Last Modified: 2011-09-20
I want to shutdown and restart Windows XP from my
program, although it is not run on an administrator
account. I tried using InitiateSystemShutdown and
ExitWindowsEx, but they didn't work(also for
administrator account). What can I do? Please, help me.
0
Comment
Question by:MikeMonroe
[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
 

Expert Comment

by:Getch
ID: 8233508
create a shortcut right click on desktop->>new->>shortcut
and then in commandline write rundll.exe user.exe,exitwindowsexec and then call it from your program... [works in win98] this will restart your pc do the same with rundll.exe user.exe,exitwindows [will shut down your pc].

...getch
0
 
LVL 4

Expert Comment

by:nestorua
ID: 8233906
HI,
If it is the local computer you can do it the following
way:
InitiateSystemShutdown('127.0.0.1',
                       'HI, Save your DATA!',
                        20,
                        TRUE,
                        TRUE);
This show you the message 'HI, Save your DATA!' and after
20 seconds shutdown your computer and then restart it.
Sincerely,
Nestorua.
0
 

Accepted Solution

by:
ZDM earned 140 total points
ID: 8235161
procedure TForm1.Button1Click(Sender: TObject);
var
   tkHandle : THandle;
   BufferLun,ret : DWORD;
   tk,tkPrevious : TTokenPrivileges;
   LID : TLargeInteger;
   LUID : TLuIDAndAttributes;
   versione : TOSVersionInfo;
begin
   BufferLun := 1024;
   ret := 0;
   versione.dwOSVersionInfoSize := sizeof(versione);
   GetVersionEx(versione);
   if versione.dwPlatformId = VER_PLATFORM_WIN32_NT then
   begin
         tkHandle := GetCurrentProcess;
         OpenProcessToken(tkHandle,TOKEN_ALL_ACCESS,tkHandle);
         LookupPrivilegeValue(PChar(''),PChar('SeShutDownPrivilege'),LID);
         LUID.Luid := LID;
         LUID.Attributes := SE_PRIVILEGE_ENABLED;
         tk.PrivilegeCount := 1;
         tk.Privileges[0] := LUID;
         AdjustTokenPrivileges(tkHandle,False,tk,BufferLun,tkPrevious,ret);
   end;
//   ExitWindowsEx(EWX_SHUTDOWN or EWX_PowerOff,0);
   ExitWindowsEx(EWX_REBOOT,0);

end;

Works for me (W2K, admin rights).
0
 

Expert Comment

by:ZDM
ID: 8235240
Just checked. Also works without admin priviledges (guest account). Probably is the same for XP.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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