1

I am using the below code for getting process information from my 32 bit application.

var process = Process.GetProcessById((int)processID);
if (process != null && process.MainModule != null && process.MainModule.FileVersionInfo != null)
{
    windowInfo.CompanyName = process.MainModule.FileVersionInfo.CompanyName;
    windowInfo.FileDescription = process.MainModule.FileVersionInfo.FileDescription;
    windowInfo.FileName = process.MainModule.FileVersionInfo.FileName;
    windowInfo.FileVersion = process.MainModule.FileVersionInfo.FileVersion;
    windowInfo.ProductName = process.MainModule.FileVersionInfo.ProductName;
    windowInfo.ProductVersion = process.MainModule.FileVersionInfo.ProductVersion;
}

It throws Win32Exception when I query the same for a 64 bit process. I tried the same in an independent application following the solution given in this post and it worked when I changed my application to be a 64 bit. I can not do the same in my main application.

Does anyone have a workaround? I just want to query the parameters inside the "if" body.
Let me know if any more further information is required.

shruti singh
  • 146
  • 11
  • As far as I know it is not possible. 32-bit application can't do anything in a 64-bit world, they just can't "see" them. – vasily.sib Sep 26 '18 at 05:53
  • in that case, I believe I will have to make another exe (which will be 64 bit), and query that through IPC and get the information? – shruti singh Sep 26 '18 at 06:28
  • Something like that. Or use `AnyCPU`, which will be runned as x64 on 64-bit systems and as x32 on others. – vasily.sib Sep 26 '18 at 06:47
  • We have a dependency due to which we would require our application to run as 32 bit in 64 bit architecture too. hence, can not use AnyCPU. – shruti singh Sep 26 '18 at 08:59
  • also, please note that you should properly dispose `process` object after use (by wrapping all this code in `using` block, for example) – vasily.sib Sep 26 '18 at 09:09
  • Yes sure. Thanks a lot. IPC is finally working for me. – shruti singh Sep 27 '18 at 10:14
  • @vasily.sib Can you please help around how can I get the 64 bit application started from 32 bit? I have tried Process.Start() and task scheduler. Both start the 64 bit application as 32 bit only. Even `Wow64DisableWow64FsRedirection` is resulting in IntPtr.Zero value. – shruti singh Oct 01 '18 at 08:40
  • you mean "start external x64 application from within x32 application code"? – vasily.sib Oct 01 '18 at 08:44
  • Yes. Currently I am using [this](https://stackoverflow.com/questions/26110621/get-x64-process-mainmodule-location-from-an-x86-application) solution. – shruti singh Oct 01 '18 at 10:21
  • The problem with the solution in above comment is, it does not give me executable paths of the applications running with admin rights, unless my application is also running with admin rights. – shruti singh Oct 01 '18 at 10:32
  • to **start** external application, you don't need any special means. Just `var processInfo = Process.Start("external_program.exe");`. Also, this starts looking like XY-problem:\ What exactly you ar trying to do? – vasily.sib Oct 01 '18 at 10:40

1 Answers1

0

This solution worked for me: Get x64 process mainmodule location from an x86 application?

I just used the relevant information from the WMI query:

(from item in searcher.Get().Cast<ManagementObject>()
                        where ((UInt32?)item["ProcessId"]).HasValue && ((UInt32?)item["ProcessId"]).Value == processID
                        select new Win32Process()
                        {
                            ExecutablePath = System.Convert.ToString(item["ExecutablePath"]),
                            ProcessId = (UInt32?)item["ProcessId"],
                        }).ToArray();

The array returned will contain the information for 64 bit applications as well, eventhough fired from a 32 bit application.

shruti singh
  • 146
  • 11