Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

Restart Windows

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
MikeMonroe
Asked:
MikeMonroe
  • 2
1 Solution
 
GetchCommented:
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
 
nestoruaCommented:
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
 
ZDMCommented:
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
 
ZDMCommented:
Just checked. Also works without admin priviledges (guest account). Probably is the same for XP.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now