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.

34 lines
829 B

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