How to use Perl to control Win32 service

xiaoxiao2021-03-06  40

Recently written a program, it is written.

View all service information

Use Win32 :: Service;

Win32 :: Service :: GetServices ('', /% soldes);

Foreach $ key (Sort Keys% Services) {Print "Display Name / T: $ KEY, $ Services {$ Key} / n"; Win32 :: Service :: getStatus ('', $ services {$ key}, /% Status); Foreach $ part (keys% status) {print "/ t $ part: $ status {$ part} / n";}}

View a single service information Win32 :: service :: getStatus ('', 'w3svc', /% status); # 中 W3SVC is a service short name, you can view the Win2000 / XP Administration Tools service to find it. Foreach $ part (keys% status) {print "/ t $ part: $ status {$ part} / n";

Open service WIN32 :: Service :: StartService ('', 'w3svc') || DIE "can't start service / n";

Close Service Win32 :: Service :: StopService ('', 'w3svc') || DIE "can't stop service / n";

转载请注明原文地址:https://www.9cbs.com/read-71748.html

New Post(0)