Loading ...
Sorry, an error occurred while loading the content.
 

Killing a process.

Expand Messages
  • Saurabh_Gupta@McAfee.com
    Hi all, I have written a code to list the running processes on windows platform. I need to kill one particular process if it exists. Please guide me. Is there
    Message 1 of 1 , Nov 28, 2005
      Hi all,

      I have written a code to list the running processes on windows platform.
      I need to kill one particular process if it exists. Please guide me. Is
      there any other way of doing that?



      use Win32::OLE qw( in );

      use Win32::OLE::Variant;



      $Machine = "\\\\.";

      $Machine = shift @ARGV if( $ARGV[0] =~ /^\\\\/ );

      #$p = "Mghtml.exe";

      #chomp $p;

      #print $pro;

      # WMI Win32_Process class

      $CLASS =
      "winmgmts:{impersonationLevel=impersonate}$Machine\\Root\\cimv2";

      $WMI = Win32::OLE->GetObject( $CLASS ) || die;

      foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in(
      $WMI->InstancesOf( "Win32_Process" ) ) )

      {

      $e;

      $pro = $Proc->{Name};

      chomp $pro;

      #print "$pro\n";

      if ($pro =~ "mghtml.exe")

      {

      printf( "% 5d) %s ", $Proc->{ProcessID}, "\n\u$pro \n" );

      print "( $Proc->{ExecutablePath} )" if( "" ne $Proc->{ExecutablePath}
      );

      print "\n";

      print "killing me :(";



      <<<what should I write here>>>



      print "\n$e ha ha ha ha ha";

      }

      }



      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.