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.
In reply to Re: Stop/start Windows services with perl
by TheFluffyOne
in thread Stop/start Windows services with perl
by trplebeam1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |