in reply to Re^3: Want to Start / Stop windows service through executing Perl Script
in thread Want to Start / Stop windows service through executing Perl Script
#Script to list all of the currently running services using WMI query use Win32::OLE; use Win32::OLE 'in'; use Win32::OLE::Const; use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my @servicestate = ("Stopped","Started"); my $computer = "localhost"; # can be set to point to other computers. +.. my $wmiObj = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV +2") or die "WMI connection failed.\n"; #List all services... #my $servSet = $wmiObj->ExecQuery("SELECT * FROM Win32_Service", "WQL" +, # wbemFlagReturnImmediately | wbemFlagForwardOnly); #Get only running services my $servSet = $wmiObj->ExecQuery("SELECT * FROM Win32_Service WHERE st +arted = 1", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $serv (in $servSet) { my $sname = $serv->{name}; my $sstate = $serv->{started}; my $ssmode = $serv->{startmode}; print "Service: " . $sname . " - " . $servicestate[$sstate] . " - " . $ssmode . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Want to Start / Stop windows service through executing Perl Script
by Corion (Patriarch) on Jun 01, 2009 at 07:50 UTC |