Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
904 B

  1. # list all services
  2. use strict;
  3. use Win32::OLE;
  4. use Win32::OLE::Enum;
  5. use Win32::OLE::Const 'Microsoft WMI Scripting V1.1 Library';
  6. use Getopt::Std;
  7. # below is the old version if you should need it.
  8. # use Win32::OLE::Const 'Microsoft WBEM Scripting V1.0 Library';
  9. use vars qw($locator $serv $opt_h $objs);
  10. ((2 == @ARGV) || (0 == @ARGV)) || die "Useage: [-h host] \n";
  11. getopts('h:') || die "Useage: [-h host] \n";
  12. $locator = Win32::OLE->new('WbemScripting.SWbemLocator') or die "loc\n";
  13. $serv = $locator->ConnectServer(($opt_h) ? $opt_h : '.');
  14. $serv->{security_}->{ImpersonationLevel} = wbemImpersonationLevelImpersonate;
  15. $objs = $serv->InstancesOf("Win32_service");
  16. print "Started\tStartMode\tStartName\tState\tName\n";
  17. foreach (Win32::OLE::Enum->new($objs)->All())
  18. {
  19. print "$_->{Started}\t$_->{StartMode}\t\t$_->{StartName}\t$_->{State}\t($_->{Name})\n";
  20. }