By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,031 Members | 1,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,031 IT Pros & Developers. It's quick & easy.

Terminate a process

P: 40
Hi.,

I need a Perl script to terminate the any running process in server. by specifying computer name and process name..

I have the following code to terminate the any process by specifying the process name in the local system...

Expand|Select|Wrap|Line Numbers
  1.  
  2.   use Win32::Process::List;
  3.   use Win32::OLE;
  4.   $Win32::OLE::Warn = 3;
  5.   $P = Win32::Process::List->new();
  6.   print "Enter the process name.exe to terminate:  ";
  7.   $name=<STDIN>;
  8.   chomp ($name);
  9.  
  10.   %list = $P->GetProcesses();
  11.   foreach  $key (keys %list)
  12.   {
  13.       #$name = "regedit.exe";
  14.       $ss = $list{$key};
  15.       if(($ss eq $name))
  16.       {
  17.           $pid=$key;
  18.       }
  19.   }
  20.   $strComputer = '.';
  21.   $intPID=$pid;
  22.   print " Process PID: $intPID\n";
  23.   $objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2:Win32_Process.Handle=\'' . $intPID . '\'');
  24.   print 'Process name: ' . $objWMIProcess->Name, "\n";
  25.   $intRC = $objWMIProcess->Terminate();
  26.  
  27.  
kindly anyone help me regarding this problem.

Thanks,
Sabarish
Dec 20 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.