in reply to Automatic Windows Reboot using Perl

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

/J\

Replies are listed 'Best First'.
Re^2: Automatic Windows Reboot using Perl
by Anonymous Monk on Jun 30, 2004 at 18:56 UTC
    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.

        This is exactly what I am looking for! Thanks!
        As mentionedby others, "run shutdown.exe", I was unable to find shutdown.exe on any WIN2K box that I have encountered.
        So.... the Win32::InitiateSystemShutdown routine works perfectly!
      You are passing 2 strings to a function that expects 2 numbers.