System.Diagnostics.ProcessModule...

  • Thread starter Thread starter arc
  • Start date Start date
A

arc

How to obtain the Module/Process Name of the application within?

Basically i am trying to simulate - GetModuleFileNameW



Trying this: (which doesnt work)



ProcessModule procModule = new ProcessModule(); //Gives an error
here without hinting on the right syntax

string szModulePath = procModule.FileName.ToString();



What is the right way of getting this working in .NET???



I even tried using GetModuleFileNameW by using [DllImport("Kernel32.dll")]
but could not marshal the second parameter right.



[DllImport("Kernel32.dll")]

public static extern IntPtr GetModuleFileNameW(

IntPtr hModule,

[MarshalAs(UnmanagedType.SafeArray)]

String[] lpFilename,

Int32 nSize

);



When I make a call could only obtain value 'C' in szModulePath instead of
'C:\\xxx\xx\x.x"

string[] szModulePath = {};

int iRetVal = (int)GetModuleFileNameW(OwnerHandle,szModulePath,MAXI_PATH);




- Arc
 
Just wondering whether this is another way to get what you're after?

http://msdn.microsoft.com/library/d...ionassemblyclassgetexecutingassemblytopic.asp

Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32
Dim Type1 As Type
' Set the Type instance to the target class type.
Type1 = Integer1.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(Integer1.GetType())
' Display the name of the assembly currently executing
Response.Write(("GetExecutingAssembly=" &
[Assembly].GetExecutingAssembly().FullName))


--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/security_bulletins/ms03-026.asp



How to obtain the Module/Process Name of the application within?

Basically i am trying to simulate - GetModuleFileNameW



Trying this: (which doesnt work)



ProcessModule procModule = new ProcessModule(); //Gives an error
here without hinting on the right syntax

string szModulePath = procModule.FileName.ToString();



What is the right way of getting this working in .NET???



I even tried using GetModuleFileNameW by using [DllImport("Kernel32.dll")]
but could not marshal the second parameter right.



[DllImport("Kernel32.dll")]

public static extern IntPtr GetModuleFileNameW(

IntPtr hModule,

[MarshalAs(UnmanagedType.SafeArray)]

String[] lpFilename,

Int32 nSize

);



When I make a call could only obtain value 'C' in szModulePath instead of
'C:\\xxx\xx\x.x"

string[] szModulePath = {};

int iRetVal = (int)GetModuleFileNameW(OwnerHandle,szModulePath,MAXI_PATH);




- Arc
 
Back
Top