This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: strange error message when running SHUTDOWN.EXE as root (administrator)
- From: "Patrick J. LoPresti" <patl at curl dot com>
- To: Marcos Lorenzo <marcos at it dot uc3m dot es>
- Cc: cygwin at cygwin dot com
- Date: 06 Nov 2002 09:05:05 -0500
- Subject: Re: strange error message when running SHUTDOWN.EXE as root (administrator)
- References: <Pine.LNX.4.44.0211061152190.10623-100000@laud.it.uc3m.es>
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/