Perl 操作 Windows 的系统服务

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/perl -w

use Win32::Service;


$host = '';
$status = Win32::Service::GetServices($host, \%services);

if ($status) {
   print_hash( \%services );
} else {
   print_error();
}


sub print_hash {
   my($hash_ref) = $_[0];
   @keys = keys( %$hash_ref );
   @sorted = sort( @keys );
   foreach $key (@sorted) {
      print "$key $$hash_ref{$key}\n";
   }
}

sub print_error {
    print Win32::FormatMessage( Win32::GetLastError() );
}