Solved

Help restarting Windows XP everyday at a certain time.

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

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 119
JAudiorecorder record freezing the app 29 89
Breakpoint doesn't stop in my variable 3 45
Delphi: sending SMS on android platform 1 94
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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