System.Diagnostics.ProcessModule...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • arc

    #1

    System.Diagnostics.ProcessModule...

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

    Basically i am trying to simulate - GetModuleFileNa meW



    Trying this: (which doesnt work)



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

    string szModulePath = procModule.File Name.ToString() ;



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



    I even tried using GetModuleFileNa meW by using [DllImport("Kern el32.dll")]
    but could not marshal the second parameter right.



    [DllImport("Kern el32.dll")]

    public static extern IntPtr GetModuleFileNa meW(

    IntPtr hModule,

    [MarshalAs(Unman agedType.SafeAr ray)]

    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)GetModuleF ileNameW(OwnerH andle,szModuleP ath,MAXI_PATH);




    - Arc



  • Ken Cox [Microsoft MVP]

    #2
    Re: System.Diagnost ics.ProcessModu le...

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

    http://msdn.microsoft.com/library/de...emblytopic.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.GetTyp e()
    ' Instantiate an Assembly class to the assembly housing the Integer type.
    SampleAssembly = [Assembly].GetAssembly(In teger1.GetType( ))
    ' Display the name of the assembly currently executing
    Response.Write( ("GetExecutingA ssembly=" &
    [Assembly].GetExecutingAs sembly().FullNa me))


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



    "arc" <archer_vonz@ho tmail.com> wrote in message
    news:uO4fNd0ZDH A.1916@TK2MSFTN GP12.phx.gbl...
    How to obtain the Module/Process Name of the application within?

    Basically i am trying to simulate - GetModuleFileNa meW



    Trying this: (which doesnt work)



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

    string szModulePath = procModule.File Name.ToString() ;



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



    I even tried using GetModuleFileNa meW by using [DllImport("Kern el32.dll")]
    but could not marshal the second parameter right.



    [DllImport("Kern el32.dll")]

    public static extern IntPtr GetModuleFileNa meW(

    IntPtr hModule,

    [MarshalAs(Unman agedType.SafeAr ray)]

    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)GetModuleF ileNameW(OwnerH andle,szModuleP ath,MAXI_PATH);




    - Arc




    Comment

    Working...