System.Diagnostics.ProcessModule...

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
 
K

Ken Cox [Microsoft MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top