?
Solved

Help restarting Windows XP everyday at a certain time.

Posted on 2008-06-11
16
Medium Priority
?
282 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
[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
  • 5
  • 4
  • 3
  • +3
16 Comments
 
LVL 19

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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 38

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 38

Expert Comment

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

800 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