Edit

Share via


ProcessModule Class

Definition

Represents a .dll or .exe file that is loaded into a particular process.

public ref class ProcessModule : System::ComponentModel::Component
public ref class ProcessModule
public class ProcessModule : System.ComponentModel.Component
public class ProcessModule
type ProcessModule = class
    inherit Component
type ProcessModule = class
Public Class ProcessModule
Inherits Component
Public Class ProcessModule
Inheritance
Inheritance
ProcessModule

Examples

The following code sample demonstrates how to use the ProcessModule class to get and display information about all the modules that are used by the Notepad.exe application.

Process^ myProcess = gcnew Process;

// Get the process start information of notepad.
ProcessStartInfo^ myProcessStartInfo = gcnew ProcessStartInfo( "notepad.exe" );

// Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' Object*.
myProcess->StartInfo = myProcessStartInfo;

// Create a notepad.
myProcess->Start();
System::Threading::Thread::Sleep( 1000 );
ProcessModule^ myProcessModule;

// Get all the modules associated with 'myProcess'.
ProcessModuleCollection^ myProcessModuleCollection = myProcess->Modules;
Console::WriteLine( "Properties of the modules  associated with 'notepad' are:" );

// Display the properties of each of the modules.
for ( int i = 0; i < myProcessModuleCollection->Count; i++ )
{
   myProcessModule = myProcessModuleCollection[ i ];
   Console::WriteLine( "The moduleName is {0}", myProcessModule->ModuleName );
   Console::WriteLine( "The {0}'s base address is: {1}", myProcessModule->ModuleName, myProcessModule->BaseAddress );
   Console::WriteLine( "The {0}'s Entry point address is: {1}", myProcessModule->ModuleName, myProcessModule->EntryPointAddress );
   Console::WriteLine( "The {0}'s File name is: {1}", myProcessModule->ModuleName, myProcessModule->FileName );
}
myProcessModule = myProcess->MainModule;

// Display the properties of the main module.
Console::WriteLine( "The process's main moduleName is: {0}", myProcessModule->ModuleName );
Console::WriteLine( "The process's main module's base address is: {0}", myProcessModule->BaseAddress );
Console::WriteLine( "The process's main module's Entry point address is: {0}", myProcessModule->EntryPointAddress );
Console::WriteLine( "The process's main module's File name is: {0}", myProcessModule->FileName );
myProcess->CloseMainWindow();
using (Process myProcess = new Process())
{
    // Get the process start information of notepad.
    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
    // Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
    myProcess.StartInfo = myProcessStartInfo;
    // Create a notepad.
    myProcess.Start();
    System.Threading.Thread.Sleep(1000);
    ProcessModule myProcessModule;
    // Get all the modules associated with 'myProcess'.
    ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
    Console.WriteLine("Properties of the modules  associated "
        + "with 'notepad' are:");
    // Display the properties of each of the modules.
    for (int i = 0; i < myProcessModuleCollection.Count; i++)
    {
        myProcessModule = myProcessModuleCollection[i];
        Console.WriteLine("The moduleName is "
            + myProcessModule.ModuleName);
        Console.WriteLine("The " + myProcessModule.ModuleName + "'s base address is: "
            + myProcessModule.BaseAddress);
        Console.WriteLine("The " + myProcessModule.ModuleName + "'s Entry point address is: "
            + myProcessModule.EntryPointAddress);
        Console.WriteLine("The " + myProcessModule.ModuleName + "'s File name is: "
            + myProcessModule.FileName);
    }
    // Get the main module associated with 'myProcess'.
    myProcessModule = myProcess.MainModule;
    // Display the properties of the main module.
    Console.WriteLine("The process's main moduleName is:  "
        + myProcessModule.ModuleName);
    Console.WriteLine("The process's main module's base address is: "
        + myProcessModule.BaseAddress);
    Console.WriteLine("The process's main module's Entry point address is: "
        + myProcessModule.EntryPointAddress);
    Console.WriteLine("The process's main module's File name is: "
        + myProcessModule.FileName);
    myProcess.CloseMainWindow();
}
Using myProcess As New Process()
    ' Get the process start information of notepad.
    Dim myProcessStartInfo As New ProcessStartInfo("notepad.exe")
    ' Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
    myProcess.StartInfo = myProcessStartInfo
    ' Create a notepad.
    myProcess.Start()
    System.Threading.Thread.Sleep(1000)
    Dim myProcessModule As ProcessModule
    ' Get all the modules associated with 'myProcess'.
    Dim myProcessModuleCollection As ProcessModuleCollection = myProcess.Modules
    Console.WriteLine("Properties of the modules  associated with 'notepad' are:")
    ' Display the properties of each of the modules.
    Dim i As Integer
    For i = 0 To myProcessModuleCollection.Count - 1
        myProcessModule = myProcessModuleCollection(i)
        Console.WriteLine("The moduleName is " + myProcessModule.ModuleName)
        Console.WriteLine("The " + myProcessModule.ModuleName.ToString() +
                   "'s base address is: " + myProcessModule.BaseAddress.ToString())
        Console.WriteLine("The " + myProcessModule.ModuleName.ToString() +
                "'s Entry point address is: " + myProcessModule.EntryPointAddress.ToString())
        Console.WriteLine("The " + myProcessModule.ModuleName +
                                "'s File name is: " + myProcessModule.FileName)
    Next i
    ' Get the main module associated with 'myProcess'.
    myProcessModule = myProcess.MainModule
    ' Display the properties of the main module.
    Console.WriteLine("The process's main moduleName is:  " + myProcessModule.ModuleName)
    Console.WriteLine("The process's main module's base address is: " +
                            myProcessModule.BaseAddress.ToString())
    Console.WriteLine("The process's main module's Entry point address is: " +
                            myProcessModule.EntryPointAddress.ToString())
    Console.WriteLine("The process's main module's File name is: " +
                            myProcessModule.FileName)
    myProcess.CloseMainWindow()
End Using

Remarks

A module is an executable file or a dynamic link library (DLL). Each process consists of one or more modules. You can use this class to get information about the module.

Important

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

Properties

BaseAddress

Gets the memory address where the module was loaded.

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container

Gets the IContainer that contains the Component.

(Inherited from Component)
DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EntryPointAddress

Gets the memory address for the function that runs when the system loads and runs the module.

Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
FileName

Gets the full path to the module.

FileVersionInfo

Gets version information about the module.

ModuleMemorySize

Gets the amount of memory that is required to load the module.

ModuleName

Gets the name of the process module.

Site

Gets or sets the ISite of the Component.

(Inherited from Component)

Methods

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ToString()

Converts the name of the module to a string.

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Applies to