Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had issues with <a href="https://stackoverflow.com/a/317209/1574221">stefan's solution</a>. Below is a modified version which seems to work well.</p> <pre><code>using System; using System.Collections; using System.Diagnostics; using System.Management; using System.IO; static class Module1 { static internal ArrayList myProcessArray = new ArrayList(); private static Process myProcess; public static void Main() { string strFile = "c:\\windows\\system32\\msi.dll"; ArrayList a = getFileProcesses(strFile); foreach (Process p in a) { Debug.Print(p.ProcessName); } } private static ArrayList getFileProcesses(string strFile) { myProcessArray.Clear(); Process[] processes = Process.GetProcesses(); int i = 0; for (i = 0; i &lt;= processes.GetUpperBound(0) - 1; i++) { myProcess = processes[i]; //if (!myProcess.HasExited) //This will cause an "Access is denied" error if (myProcess.Threads.Count &gt; 0) { try { ProcessModuleCollection modules = myProcess.Modules; int j = 0; for (j = 0; j &lt;= modules.Count - 1; j++) { if ((modules[j].FileName.ToLower().CompareTo(strFile.ToLower()) == 0)) { myProcessArray.Add(myProcess); break; // TODO: might not be correct. Was : Exit For } } } catch (Exception exception) { //MsgBox(("Error : " &amp; exception.Message)) } } } return myProcessArray; } } </code></pre> <p><strong>UPDATE</strong></p> <p>If you just want to know which process(es) are locking a particular DLL, you can execute and parse the output of <code>tasklist /m YourDllName.dll</code>. Works on Windows XP and later. See</p> <p><a href="https://stackoverflow.com/questions/152506/what-does-this-do-tasklist-m-mscor">What does this do? tasklist /m &quot;mscor*&quot;</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload