Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Has anyone seen code to call EnumProcessModules and EnumProcesses from C# lately?

Got a setup shim pogram all written in C# and need to determine if any process has a DLL loaded prior to copying files.

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 1-May-12 18:47pm    
I wonder why would you need this in .NET, where the concept of modules is different from native Windows API?
--SA

1 solution

From: Wes Aday : Would Process.GetProcesses() not do the same thing?

Yes it would. Thanks for the tip.

Collect array of processes:
C#
// Get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();

For each process get the modules:
ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;

For each module process the filename:
myProcessModule = myProcessModuleCollection[i];
myProcessModule.FileName

That's what I need to do.

By modules, I mean I need to know exxactly which DLL and the filepath to them any process has loaded. You cannot replace a DLL if it is in use by a program.
 
Share this answer
 
v2
Comments
[no name] 2-May-12 10:57am    
Good for you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900