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

Terminate a process by specifing computer name using PERL..

P: 40
Hi.,

I am using the following code to terminate the any process by giving the process name as input...

Expand|Select|Wrap|Line Numbers
  1. use Win32::Process::List;
  2. use Win32::OLE;
  3. $Win32::OLE::Warn = 3;
  4. $P = Win32::Process::List->new();
  5. print "Enter the process name.exe to terminate:  ";
  6. $name=<STDIN>;
  7. chomp ($name);
  8.  
  9. %list = $P->GetProcesses();
  10. foreach  $key (keys %list) 
  11. {
  12.     #$name = "regedit.exe";
  13.     $ss = $list{$key};
  14.     if(($ss eq $name))
  15.     {
  16.         $pid=$key;
  17.     }
  18. }
  19. $strComputer = '.';
  20. $intPID=$pid;
  21. print " Process PID: $intPID\n";
  22. $objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2:Win32_Process.Handle=\'' . $intPID . '\'');
  23. print 'Process name: ' . $objWMIProcess->Name, "\n";
  24. $intRC = $objWMIProcess->Terminate();
  25.  
  26.  
If I run the above script in server., I am in trouble by terminate the process by specifying computer name.. if one or more users using the same application

kindly anyone help me regarding this problem...
Dec 20 '07 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi.,

I am using the following code to terminate the any process by giving the process name as input...

Expand|Select|Wrap|Line Numbers
  1. use Win32::Process::List;
  2. use Win32::OLE;
  3. $Win32::OLE::Warn = 3;
  4. $P = Win32::Process::List->new();
  5. print "Enter the process name.exe to terminate:  ";
  6. $name=<STDIN>;
  7. chomp ($name);
  8.  
  9. %list = $P->GetProcesses();
  10. foreach  $key (keys %list) 
  11. {
  12.     #$name = "regedit.exe";
  13.     $ss = $list{$key};
  14.     if(($ss eq $name))
  15.     {
  16.         $pid=$key;
  17.     }
  18. }
  19. $strComputer = '.';
  20. $intPID=$pid;
  21. print " Process PID: $intPID\n";
  22. $objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2:Win32_Process.Handle=\'' . $intPID . '\'');
  23. print 'Process name: ' . $objWMIProcess->Name, "\n";
  24. $intRC = $objWMIProcess->Terminate();
  25.  
  26.  
If I run the above script in server., I am in trouble by terminate the process by specifying computer name.. if one or more users using the same application

kindly anyone help me regarding this problem...
Ok, this is your friendly reminder before the warning. When posting code in the forums, please remember to surround the code in the necessary, required code tags.

Thank you!

Regards,

Jeff
Dec 20 '07 #2

P: 40
Hi Jeff,,

I am new in this forum site..
I will use the code tags in future...

Thanks.
Dec 20 '07 #3

Post your reply

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