Solved

Help restarting Windows XP everyday at a certain time.

Posted on 2008-06-11
16
278 Views
Last Modified: 2010-04-21
Well my title sums up my question. I need to restart Windows XP everyday at a certain time. Do I need to use a timer to check the time?

Thanks
0
Comment
Question by:DigitalNam
  • 5
  • 4
  • 3
  • +3
16 Comments
 
LVL 18

Expert Comment

by:Mal Osborne
ID: 21757864
Fairly simple, you need write a script that uses the SHUTDOWN command, then fire it with task scheduler.   Type "shutdown" at a command prompt for a template, go to "Control panel", "Sheduled tasks" to add a task.

0
 
LVL 1

Author Comment

by:DigitalNam
ID: 21757883
Any other solution malmensa? I do not want to use the windows task scheduler.
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21757887
You just need a scheduled task to perform a reboot, it's prebuilt into windows.

It should have existing schedules for scandisk/ddefrag etc, look at them and create one for a shutdown/reboot
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
LVL 1

Expert Comment

by:bolt81
ID: 21757889
Create a schedule task that runs %SystemRoot%\System32\shutdown.exe -r -t 00

this will restart immediately at the time you set in the schedule.

use -s to shutdown instead of restart
change 00 to how many seconds to wait before restart
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21757900
Hmm, why don't you want to use windows task scheduler?
It's free and already installed - that's its purpose to perform scheduled operations - it sits in the taskbar and waits to run tasks.

Unless you want to write something yourself in Visual Basic that isn't obvious to a user and unknown to them reboots the PC - but applications like that may not work given antivirus software etc; best to use the approved Microsoft Program so you know for certain it iwll work.
0
 
LVL 13

Accepted Solution

by:
ThievingSix earned 125 total points
ID: 21757948
1) Start a new application.
2) Remove Unit1(Project Menu --> Remove From Project).
3) View project source(Project Menu --> View Source).
4) Paste below code editing constants.

.::Kind a simplistic way to do this, but it works.::.
program RestartScheduler;
 
uses
  Windows,
  SysUtils;
 
{$R *.res}
 
function RestartWindows: Boolean;
var
  TTokenHd: THandle;
  TTokenPvg: TTokenPrivileges;
  cbtpPrevious: DWORD;
  rTTokenPvg: TTokenPrivileges;
  pcbtpPreviousRequired: DWORD;
  tpResult: Boolean;
const
  SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
  If (Win32Platform = VER_PLATFORM_WIN32_NT) Then
    begin
    tpResult := OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY,TTokenHd);
    If (tpResult) Then
      begin
      tpResult := LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,TTokenPvg.Privileges[0].Luid);
      TTokenPvg.PrivilegeCount := 1;
      TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      cbtpPrevious := SizeOf(rTTokenPvg);
      pcbtpPreviousRequired := 0;
      If (tpResult) Then
        begin
        AdjustTokenPrivileges(TTokenHd,False,TTokenPvg,cbtpPrevious,rTTokenPvg,pcbtpPreviousRequired);
      end;
    end;
  end;
  Result := ExitWindowsEx(EWX_REBOOT Or EWX_FORCE,0);
end;
 
const
  ShutdownTime : String = '12:00:00 am';
//ShutdownTime : String = '04:43:23 am';
//ShutdownTime : String = '08:02:12 pm';
var
  CurrentTime : String;
begin
  While (1 = 1) Do
    begin
    CurrentTime := FormatDateTime('hh:nn:ss am/pm',Now);
    If (CurrentTime = ShutdownTime) Then
      begin
      While Not RestartWindows Do
        begin
        Sleep(1000);
      end;
    end;
    Sleep(1000);
  end;
end.

Open in new window

0
 
LVL 1

Author Comment

by:DigitalNam
ID: 21758051
ThievingSix: this looks like what I am looking for. Don't have time to test it now,but will test it within the next few hours and award points. Thanks.
0
 
LVL 13

Expert Comment

by:ThievingSix
ID: 21758113
The only thing I can say about the code is when setting the ShutdownTime constant, use the format: "00:00:00 am". No more characters, no less.

Also you might want to change the final Sleep(1000) to Sleep(500) or Sleep(750)  because there is a slight chance that it will miss your time by a second if you don't.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21758161
ThievingSix -->

1) Start a new application.
2) Remove Unit1(Project Menu --> Remove From Project).
3) View project source(Project Menu --> View Source).

this looks like the Create Console Application button
0
 
LVL 13

Expert Comment

by:ThievingSix
ID: 21763317
No. This isn't a console app. It would have to say {$APPTYPE Console} for that.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21766190
yeah, the only line would then be :
delete {$APPTYPE Console} line :)
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21766193
and off course
uses windows, sysutils;
0
 
LVL 13

Expert Comment

by:ThievingSix
ID: 21766406
True, same thing in the end.
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 21821282
Sorry for not responding for a while but one of the perks of living in a small town in Namibia is the lack of a reliable internet connection :-)

Thieving: This may sound stupid but how do I integrate your solution into an already existing project? I copied and pasted it in my current project but with the function, all code after it is ignored. Maybe I am overlooking something or just being stupid...
0
 
LVL 1

Author Closing Comment

by:DigitalNam
ID: 31466055
thank you for the help. sorry it took so long to award the points.
0
 
LVL 13

Expert Comment

by:ThievingSix
ID: 21860770
Put this in a timer
    CurrentTime := FormatDateTime('hh:nn:ss am/pm',Now);
    If (CurrentTime = ShutdownTime) Then
      begin
      While Not RestartWindows Do
        begin
        Sleep(1000);
      end;
    end;
    Sleep(1000);

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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