帅帅男孩 发表于 2018-8-31 07:28:41

perl windows杀进程

use Win32::OLE;  
use Win32::Process;
  
use Cwd;
  
##下面枚举机器中正在运行的所有进程信息
  
$wmi = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2');##两种方法都可以的
  
$plist = $wmi->InstancesOf("Win32_Process");
  
my $dir = getcwd;
  
my $FilePath =$dir."\\杀死进程.txt";
  
print "file is哈 $FilePath";
  
my @FileContent = GetFileContent($FilePath);
  
$n = 0;
  
foreach $Proc (Win32::OLE::in( $plist )){
  
print $Proc->{'Name'},".\n";
  
my $name = $Proc->{'Name'};
  
my $ID = $Proc->{'ProcessID'};
  
print $Proc->{'ProcessID'},".\n";
  
my $test = ;
  
if($name ~~ @FileContent)
  
{
  
print $name;
  
my $test = ;
  
Win32::Process::KillProcess($Proc->{'ProcessID'},0);
  
}
  
$n++;
  
}
  
sub GetFileContent
  
{
  
my $filePath = shift;
  
if(!-e $filePath)
  
{
  
die "the $filePathdoes not exits $!";
  
}
  
print "is in\n";
  
open (InputFile ,"$filePath" ) || die "can not read file $! \n";
  
my @InputArray;
  
while(my $line = )
  
{
  
print "the line is $line\n";
  
my @Temp = split /,/,$line;
  
push(@InputArray,@Temp);
  
}
  
@InputArray;
  
}


页: [1]
查看完整版本: perl windows杀进程