Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ProcessModule Class

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

For a list of all members of this type, see ProcessModule Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Diagnostics.ProcessModule

[Visual Basic]
Public Class ProcessModule
   Inherits Component
[C#]
public class ProcessModule : Component
[C++]
public __gc class ProcessModule : public Component
[JScript]
public class ProcessModule extends Component

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

Example

[Visual Basic] 
Dim 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()

[C#] 
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();

[C++] 
Process* myProcess = new Process();
// Get the process start information of notepad.
ProcessStartInfo* myProcessStartInfo = new ProcessStartInfo(S"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(S"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->Item[i];
    Console::WriteLine(S"The moduleName is {0}", myProcessModule->ModuleName);         
    Console::WriteLine(S"The {0}'s base address is: {1}",myProcessModule->ModuleName,
        __box(myProcessModule->BaseAddress));
    Console::WriteLine(S"The {0}'s Entry point address is: {1}", 
        myProcessModule->ModuleName, __box(myProcessModule->EntryPointAddress));
    Console::WriteLine(S"The {0}'s File name is: {1}", myProcessModule->ModuleName,
        myProcessModule->FileName);
}
// Get the main module associated with 'myProcess'.
myProcessModule = myProcess->MainModule;
// Display the properties of the main module.
Console::WriteLine(S"The process's main moduleName is: {0}",
    myProcessModule->ModuleName);     
Console::WriteLine(S"The process's main module's base address is: {0}",
    __box(myProcessModule->BaseAddress));
Console::WriteLine(S"The process's main module's Entry point address is: {0}",
    __box(myProcessModule->EntryPointAddress));
Console::WriteLine(S"The process's main module's File name is: {0}",
    myProcessModule->FileName);
myProcess->CloseMainWindow();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Diagnostics

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

ProcessModule Members | System.Diagnostics Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.