in reply to Stop/start Windows services with perl
I have a script that uses the Win32::Service module to start a service, and it's fairly straightforward to change it to a stop instead. I find it's easier to deal with return codes from a module than a shelled-out "net start" or "net stop".
Have snipped out the important bit:
use Win32::Service; $ServiceName = "SomeService"; sub StartRCS { print "Attempting to start Radia Configuration Server\n"; my %ServiceHash = (); Win32::Service::GetStatus('', $ServiceName, \%ServiceHash); if (%ServiceHash) { if ($ServiceHash{CurrentState} != Win32::Service->SERVICE_RUNN +ING) { if (Win32::Service::StartService('', $ServiceName)) { print "RCS Service start command completed successfull +y"; } else { print "RCS could not be started"; } } else { print "RCS Service already appears to be running"; } } else { print "'$ServiceName' service doesn't exist"; } }
Update: Realised the case of $ServiceName was incorrect.
Hope that helps...
Gordon.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (2) Stop/start Windows services with perl
by trplebeam1 (Initiate) on Nov 21, 2003 at 19:33 UTC | |
by TheFluffyOne (Beadle) on Nov 22, 2003 at 09:17 UTC |