delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/11/06/09:05:28

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
To: Marcos Lorenzo <marcos AT it DOT uc3m DOT es>
Cc: cygwin AT cygwin DOT com
Subject: Re: strange error message when running SHUTDOWN.EXE as root (administrator)
References: <Pine DOT LNX DOT 4 DOT 44 DOT 0211061152190 DOT 10623-100000 AT laud DOT it DOT uc3m DOT es>
From: "Patrick J. LoPresti" <patl AT curl DOT com>
Date: 06 Nov 2002 09:05:05 -0500
In-Reply-To: <mit.lcs.mail.cygwin/Pine.LNX.4.44.0211061152190.10623-100000@laud.it.uc3m.es>
Message-ID: <s5gbs523ib2.fsf@egghead.curl.com>
Lines: 65
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
MIME-Version: 1.0

The Perl script below should give you a better error message.  Just
save it as "shutdown.pl"; run it with "--help" for usage instructions.
You need to run it under ActiveState Perl, not Cygwin Perl.  (Unless
Cygwin Perl includes the Win32API module, which I believe it does
not.)

 - Pat


# Shut down a Windows workstation.

use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use Win32API::Registry qw(:Func :SE_);

# Your usual option-processing sludge.
my %opts;
GetOptions (\%opts, 'help|h|?', 'message=s', 'halt', 'reboot', 'timeout=i')
    or pod2usage (2);

(exists $opts{'help'})
    and pod2usage ('-exitstatus' => 0, '-verbose' => 2);

# Ensure no arguments after options
@ARGV == 0
    or pod2usage (2);

(exists $opts{'halt'} != exists $opts{'reboot'})
    or die "$0: You must specify exactly one of --halt or --reboot\n";

my $timeout = (exists $opts{'timeout'} ? $opts{'timeout'} : 10);
my $reboot = exists $opts{'reboot'};
my $message = (exists $opts{'message'} ? $opts{'message'}
               : "$0 is shutting down the system");

# Enable "shutdown" privilege
AllowPriv (SE_SHUTDOWN_NAME, 1)
    or die "Unable to AllowPriv SE_SHUTDOWN_NAME: $^E";

InitiateSystemShutdown ('', $message, $timeout, 1, $reboot)
    or die "Unable to InitiateSystemShutdown: $^E";

print "Shutdown initiated.\n";

exit 0;

__END__

=head1 NAME

shutdown.pl - Shut down a Windows system

=head1 SYNOPSIS

shutdown.pl [ options ]

=head1 OPTIONS

 --help                  Display help and exit
 --message=<msg>         Display <msg> in message box during countdown
 --halt                  Shut down and halt
 --reboot                Shut down and reboot
 --timeout=<secs>        Wait <secs> seconds before shutdown (default 10)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019