http://www.perlmonks.org?node_id=370794

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks:
Essentially what I would like to do is reboot Windoz once a month. I would like to do this via a Perl Script placed in the Windows Scheduler. Is there a specific Win32 module that will allow me to accomplish this?

As always, your wisdom is greatly appreciated.
Thank you in advance for your help.

Replies are listed 'Best First'.
Re: Automatic Windows Reboot using Perl
by BrowserUk (Patriarch) on Jun 30, 2004 at 17:06 UTC

    You could just schedule the shutdown command

    P:\test>shutdown Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t +xx] [-c "comment"] [-d up:xx:yy] No args Display this message (same as -?) -i Display GUI interface, must be the fir +st option -l Log off (cannot be used with -m option +) -s Shutdown the computer -r Shutdown and restart the computer -a Abort a system shutdown -m \\computername Remote computer to shutdown/restart/ab +ort -t xx Set timeout for shutdown to xx seconds -c "comment" Shutdown comment (maximum of 127 chara +cters) -f Forces running applications to close w +ithout warning -d [u][p]:xx:yy The reason code for the shutdown u is the user code p is a planned shutdown code xx is the major reason code (positive +integer less than 256) yy is the minor reason code (positive +integer less than 65536)

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
Re: Automatic Windows Reboot using Perl
by gellyfish (Monsignor) on Jun 30, 2004 at 16:25 UTC

    You probably want to use ExitWindowsEx() from User32.dll via Win32::API - EWX_REBOOT has the value of 4 ...

    /J\

      An excellent start in the right direction for me.
      The WINDOZ version I am using is Windows 2000 (currentlyt testing on). This may also go on XP. ANyway what I get is exiting, not always cleanly, back to the Win2K login window. The goal is to reboot straight through no questions asked. I have posted the code below. What subtly am I missing??
      #!/usr/bin/perl -w use strict; use Win32::API; Win32::API->Import( 'User32', 'BOOL ExitWindowsEx( DWORD uFlags, DWORD dwReason )', ); ExitWindowsEx('EWX_REBOOT','4');
      Your help is greatly appreciated! Thanks!
        Although I agree with the other posters in that if all you want is to reboot the computer you should just use shutdown.exe, if you need a Perl solution (say for the end of a Perl script in which you desire a reboot), this is what I use:

        Win32::InitiateSystemShutdown( '', "\nAction Complete.\n\nSystem will now Reboot\!", 20, 0, 1 );

        - - arden.

        You are passing 2 strings to a function that expects 2 numbers.
Re: Automatic Windows Reboot using Perl
by gawatkins (Monsignor) on Jun 30, 2004 at 17:12 UTC

    Unless you have a reason for specifically using Perl, the shutdown.exe program that is usually located in %systemroot%\system32 directory will allow you to easily perform your task. Just type shutdown.exe /? at the command prompt to display the options.

    Thanks,
    Greg

    UPDATE: or you could just read the above post Re: Automatic Windows Reboot using Perl

Re: Automatic Windows Reboot using Perl
by skyknight (Hermit) on Jun 30, 2004 at 19:09 UTC

    I dunno about Perl, but the following C code will work on any Windows OS that is based on the NT kernel...

    while(1) { printf("\t\t\b\b\b"); }

    I think it will even work if you are not Administrator. ;-)

Re: Automatic Windows Reboot using Perl
by zentara (Archbishop) on Jul 01, 2004 at 14:06 UTC
    I havn't used windows regularly for quite some time, but I'm amazed that you can go a full month without having to reboot. I remember lockups at least once a day.

    I'm not really a human, but I play one on earth. flash japh
      Oh c'mon... I have windows servers all the time that are up for 6+ months. Lately though hotfixes/security fixes have been a real downer on the uptime. I assure you it is possible, though I'd also agree that its difficult due to how complex windows is.
      I havn't used windows regularly for quite some time

      Things have changed.