Solved

Help restarting Windows XP everyday at a certain time.

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

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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 36

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 36

Expert Comment

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now