JasonDavis has asked for the wisdom of the Perl Monks concerning the following question:
use strict; my $cons; my %service; my %status; my $CONSOLE; my $key; my $continue="y"; my $option; my @sorted; my $counter=0; my $stop; my $start; my $current_date; my $input; my $kill; my $running; my $service_name; my $user_selection; my $hostname; my %codes; my %services; my $service; my $codes; my %statcode; use Win32::Console; use Win32::Service; Win32::Service::GetServices("", \%service); my @sorted=sort(keys(%service)); $cons = Win32::Console->new (STD_OUTPUT_HANDLE); $current_date = localtime(time); %codes = ( 1 => "Stopped.", 2 => "Starting.", 3 => "Stopping.", 4 => "Running.", 5 => "Continue.", 6 => "Pausing.", 7 => "Paused.", 8 => "Unknown.", 9 => "Unknown." ); while ($continue eq "y") { $cons->Cls(); print "\n\n\n\n"; print "\t----------------------------------------------------\n"; + #Menu heading print "\t \t Windows Services Status Viewer\n"; print "\t----------------------------------------------------\n\n" +; print "\t 1. Service names started in ascending order.\n"; print "\t 2. Service names stopped in ascending order.\n"; print "\t 3. Exit.\n\n"; print "\t----------------------------------------------------\n"; + #Menu heading print "\t \t\t Version 1.0\n"; print "\t \t $current_date\n"; print "\t----------------------------------------------------\n\n" +; print "\n\n\t\t Select option (1 to 3) = "; my $option=<STDIN> ; if ($option == 1) { started(); } else { if ($option == 2) { stopped(); } else { if ($option == 3) { print "\t--------------------------------------------- +-------\n"; print "\t \t\t Goodbye print "\t--------------------------------------------- +-------\n\n"; $continue="n"; } else { if ($option != [1-3]) { print "Please enter a valid a valid option (1 - 3) +\n"; system ("pause"); } } } } } sub started { $counter=0; foreach $key(@sorted) { $counter++; @sorted=sort(keys(%service)); Win32::Service::GetStatus("", $service{$key}, \%status +); if ($status{CurrentState} == 4) { print "\t$counter\t$key\n" ; } } print "Please enter the number of the service to terminate +:\n"; chomp($user_selection = <STDIN>); Win32::Service::GetServices ("", \%service); foreach (sort(keys(%service))) { $service_name = $_; Win32::Service::GetStatus ("", $service{$key}, \%statu +s); $running = $status{"CurrentState"}; if (("$service_name" eq "$user_selection") and ("$running" eq "4")) { print "$service_name $codes{$running} and will be +stopped\n"; Win32::Service::StopService ("", $service_name); print "$service_name has been stopped! \n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Stopping Service with Win32::StopService
by GrandFather (Saint) on Jun 26, 2008 at 12:35 UTC | |
by JasonDavis (Novice) on Jun 30, 2008 at 02:28 UTC | |
by BrowserUk (Patriarch) on Jun 30, 2008 at 03:39 UTC | |
by JasonDavis (Novice) on Jul 01, 2008 at 00:27 UTC | |
by BrowserUk (Patriarch) on Jul 01, 2008 at 03:41 UTC | |
|
Re: Stopping Service with Win32::StopService
by Rabbi Bob (Scribe) on Jun 26, 2008 at 10:52 UTC |