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.

28 lines
809 B

  1. # kill a process
  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 $opt_x $obj);
  10. ((2 == @ARGV) || (4 == @ARGV)) || die "Useage: [-h host] -x procId \n";
  11. getopts('x:h:') || die "Useage: [-h host] -x procId \n";
  12. ($opt_x) || die "Useage: [-h host] -x procId \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. $obj = $serv->Get("Win32_Process.Handle=\"$opt_x\"");
  17. $obj->Terminate();