Solved

Help restarting Windows XP everyday at a certain time.

Posted on 2008-06-11
16
277 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 17

Expert Comment

by:Malmensa
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
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 89
FMX enumerated colours 2 99
Working with hours 3 57
Create a path if not exists 7 77
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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