다음을 통해 공유


How to: Investigate Libraries Loaded by Processes 

The Modules property of the Process component provides access to the loaded libraries for a process. The Modules property returns a collection of the type ProcessModuleCollection, which includes all loaded libraries for the target process. You can then iterate through the collection to look at individual libraries.

To investigate library usage for a process

  1. If the target process was not started by a Process component, bind a new instance of a Process component to the process. For more information, see How to: Bind to Existing Processes.

  2. Declare an object of type ProcessModuleCollection to hold the module collection.

  3. Assign the Modules property to the ProcessModuleCollection variable. This populates the ProcessModuleCollection object with the modules from the target module.

  4. Iterate through the ProcessModuleCollection object to view and manage individual libraries.

    The following example shows how to return all loaded libraries for Microsoft Word and then display the items in a ListBox control:

    Dim WordProcesses() As Process
    Dim WordModules As ProcessModuleCollection
    Dim aModule As ProcessModule
    WordProcesses = Process.GetProcessesByName("WinWord")
    ' Populate the module collection.
    WordModules = WordProcesses(0).Modules
    ' Iterate through the module collection.
    For Each aModule In WordModules
        ListBox1.Items.Add(aModule.ModuleName)
    Next
    
    Process[] wordapps;
    ProcessModuleCollection modules;
    wordapps = Process.GetProcessesByName("WinWord");
    // Populate the module collection.
    modules = wordapps[0].Modules;
    // Iterate through the module collection.
    foreach (ProcessModule aModule in modules)
    {
        Listbox1.Items.Add(aModule.ModuleName);
    }
    

See Also

Tasks

How to: Create Process Components
How to: Bind to Existing Processes
Process Control Sample
Managing Processes Sample

Other Resources

Managing Processes
Retrieving Information About Processes