Dwight,
I have written a script to do the a lot of the same functions. I
found the same problem, that the service status changes do not register
correctly inside my scripts (e.g. I want to verify the service paused
before stopping it). The paused I added seemed to help. Also you will
also have problems if do not use the short NT names. Use the '-e true'
switch to view service names with their corresponding short names.
Disclaimer: I am a novice perler, so there may well be better ways to
do this - but it works for me.
Good luck.
###########################################################################
#v1.0
#BounceService.pl
#Author - Terry Z.
#Stop and restarts given $Serivce. Logs output to $LogName.
#
#$opt_s command line -s switch => service name
#$opt_c command line -c switch => computer name
#$opt_e command line -e switch => enumerate option, set to true if required
#
#Be sure to use the abreviated name. Run the '-e true' for complete list
#of service names and abreviated names.
#
###########################################################################
my(
$Service,
$ComputerName,
$LogName,
$Enumerate,
$LoopCount
);
$LogName = "BounceService.log";
use Win32::Service;
use Getopt::Std;
getopt('sce:');
$Service = "";
$ComputerName = "";
if ($opt_c)
{
$ComputerName = $opt_c;
};
if ($opt_e)
{
############################################################
#If Enumeration flag set then display all services on designates
computer.
############################################################
Win32::Service::GetServices($ComputerName, \%service);
while (($service_name, $service_short) = each(%service))
{
print "\nServiceName - $service_name => ShortName -
$service_short\n";
}
}
else
{
############################################################
#Collect command line parameters
############################################################
if ($opt_s)
{
$Service = $opt_s;
}
else
{
print "\nMissing required parameters\n\n";
print "Eg. perl bounceserver.pl -s alerter -c hq_utility02 will
bounce alerter on hq_utility01\n\n";
print "Eg. perl bounceserver.pl -e true -c hq_utility01 to
enumerate service names on hq_utility01\n";
exit;
};
open(LOGFILE, ">>$LogName") || die "Unable to open $LogName - $!";
print LOGFILE localtime(time) . "\n";
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
print LOGFILE "\tBeginning Status of $ComputerName:$Service is $status
{'CurrentState'} \n";
############################################################
#Pause $Service and wait for command to take effect.
############################################################
$ret_val = Win32::Service::PauseService($ComputerName, $Service);
sleep(10);
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
$LoopCount = 0;
while (($status{"CurrentState"} != "7"))
{
sleep(10);
$LoopCount++;
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
}
print LOGFILE "\t2nd Status of $ComputerName:$Service is $status
{'CurrentState'}. Attempts=$LoopCount\n";
############################################################
#Stop $Service and pause (for stop command to take effect).
############################################################
$ret_val = Win32::Service::StopService($ComputerName, $Service);
sleep(10);
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
$LoopCount = 0;
while (($status{"CurrentState"} != "1"))
{
sleep(10);
$LoopCount++;
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
}
print LOGFILE "\t3rd Status of $ComputerName:$Service is $status
{'CurrentState'}. Attempts=$LoopCount\n";
############################################################
#Start Service
############################################################
$ret_val = Win32::Service::StartService($ComputerName, $Service);
sleep(10);
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
$LoopCount = 0;
while (($status{"CurrentState"} != "4"))
{
sleep(10);
$LoopCount++;
$ret_val = Win32::Service::GetStatus($ComputerName, $Service,
\%status);
}
print LOGFILE "\tFinal Status of $ComputerName:$Service is $status
{'CurrentState'}. Attempts=$LoopCount.\n\n";
close(LOGFILE);
if ($status{'CurrentState'} != 4) {exit 1};
};
"Oakey, Dwight"
<[EMAIL PROTECTED]> To: 'ActivePerl Mailing
List' <[EMAIL PROTECTED]>
Sent by: cc:
[EMAIL PROTECTED] Subject: Help please,
again.
eState.com
11/02/00 05:12 PM
"So little to do, and so much time to do it in...
No, wait - reverse that." - Willie Wonka
Well, I'm fighting a tight deadline and I'm having trouble with
Win32::Service. I'm trying to write a program that will check
services, stop them, change their account password, and then
start them back up. I've got all the logic, but this Module
doesn't see to work right. First off, it reports some services
that are Stopped as Running, and others that are Running it
says are Stopped. And the big kicker is that I can't, for the
life of me, figure out how to Stop or Start a Service. The
commands don't seem to work. $? returns a 0 (fail code),
and $! returns nothing (it's a blank line.)
I have one day left to complete this assignment. Please, can
someone help me out? After some of what I've been reading
today, I'm wondering if I have a bad module. Here are the
data I could find for you:
perl, v5.6.0, Build 613
Win32-Service.zip, created 6/8/00
Service.pm, created 3/14/00
Service.pm version 0.04, written by Douglas Lankshear and
Gurusamy
Sarathy
Is it acceptable for me to e-mail one or both of these guys, directly?
Can or should I try to update either my Perl or my Service.pm?
Thanks, all.
Dwight T. Oakey, Enterprise Network Engineer
ENTEX IT Service - RNS
Mason, Oh.
Phone: (513) 573-9174 x4537
Pager: 888-452-0646 or [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Fax: (513) 336-1979
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl