#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"; }
In reply to Re^4: Want to Start / Stop windows service through executing Perl Script
by meet_arc
in thread Want to Start / Stop windows service through executing Perl Script
by meet_arc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |