ProcessModule.FileName 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取模块的完整路径。
public:
property System::String ^ FileName { System::String ^ get(); };
public string? FileName { get; }
public string FileName { get; }
member this.FileName : string
Public ReadOnly Property FileName As String
属性值
定义模块位置的完全限定路径。
示例
下面的代码示例为 Notepad.exe 应用程序创建一个新进程。 代码循环访问 ProcessModuleCollection 类以获取集合中每个模块的 ProcessModule 对象。 ModuleName 和 FileName 属性用于显示每个模块的模块名称和完整路径信息。
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( "File names of the modules associated with 'notepad' are:" );
// Display the 'FileName' of each of the modules.
for ( int i = 0; i < myProcessModuleCollection->Count; i++ )
{
myProcessModule = myProcessModuleCollection[ i ];
Console::WriteLine( "{0:s} : {1:s}", myProcessModule->ModuleName, myProcessModule->FileName );
}
myProcessModule = myProcess->MainModule;
// Display the 'FileName' of the main module.
Console::WriteLine( "The process's main module's FileName 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("File names of the modules associated "
+ "with 'notepad' are:");
// Display the 'FileName' of each of the modules.
for (int i = 0; i < myProcessModuleCollection.Count; i++)
{
myProcessModule = myProcessModuleCollection[i];
Console.WriteLine(myProcessModule.ModuleName + " : "
+ myProcessModule.FileName);
}
// Get the main module associated with 'myProcess'.
myProcessModule = myProcess.MainModule;
// Display the 'FileName' of the main module.
Console.WriteLine("The process's main module's FileName 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("File names of the modules associated " +
"with 'notepad' are:")
' Display the 'FileName' of each of the modules.
Dim i As Integer
For i = 0 To myProcessModuleCollection.Count - 1
myProcessModule = myProcessModuleCollection(i)
Console.WriteLine(myProcessModule.ModuleName + " : " + myProcessModule.FileName)
Next i
' Get the main module associated with 'myProcess'.
myProcessModule = myProcess.MainModule
' Display the 'FileName' of the main module.
Console.WriteLine("The process's main module's FileName is: " + myProcessModule.FileName)
myProcess.CloseMainWindow()
End Using
注解
如果文件名长度超过了允许的最大字符数,则文件名将被截断。