Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Kill() Access Denied

Tags:

When I run the following code, a Win32Exception is thrown for Access Denied. I cannot find any solutions via search. How do I fix this?

foreach (ListViewItem list in showprocesses.SelectedItems) {     Process p = System.Diagnostics.Process.GetProcessById(Convert.ToInt32(list.Tag));     if (p != null)         p.Kill(); } 
like image 759
Ezzy Avatar asked Aug 08 '13 15:08

Ezzy


People also ask

How do I kill a Windows Access Denied process?

Type taskkill /im process-name /f and press Enter. You can get the process name by right clicking the process you want to kill (from the Task Manager) and selecting Details. This will open the Details tab with your process already selected. Simply look at the name of the process and type it in the process-name.

Does taskkill require admin?

Taskkill is a program that needs administrative privileges to kill a task. If you start command prompt as admin and run the same command, it will succesfully kill the task.


2 Answers

You will generally get this error if you do not have the necessary permissions. You must be an administrator, and in win vista and above, run your app/process in elevated mode. Furthermore, there are certain processes that even as admin you won't be able to kill, some deemed system critical, etc, and you may need to run as system, and then there are those that even system can't kill, like antivirus, or an actual virus, because they don't want you killing their process

Another possibility is that if the process is already terminating, it will also throw that exception, see MSDN

like image 134
Jason Avatar answered Sep 20 '22 19:09

Jason


I had this kind of problems with a Delphi application Under Windows 8.1 My application was closing, but was still in the background processes of the task manager. Impossible to kill it with TaskKill (tried admin mode, "/F" option, from command line...) Finally I found out that Windows "marked" a DLL of my application as "IgnoreFreeLibrary". That is why my application was not closing. Here is an extract of the registry :

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers] "{MyApplicationPathAndExeName}"="$ IgnoreFreeLibrary<DllWithProblemName.Dll>" 

I erased the registry entry and everything was back to normal.

like image 37
Henry Kerval Avatar answered Sep 20 '22 19:09

Henry Kerval