LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to determine if an application is 32-bit or 64-bit?

Solved!
Go to solution

The snipped as shown by klynn is wrong. The IsWow64Process() function takes two parameters as shown on MSDN. The snipped only passes the handle to the function, not a second parameter to receive the boolean status if the process is a Wow64 process. In addition, the Windows handle returned by the .Net node is not directly the Window handle but a .Net object refnum. You would need to convert it to an Int64 value first through a .Net Invoke Node, before passing it to the Call Library Node as Window handle, and configure that parameter as pointer sized integer instead.

 

To add even more trouble that function only returns true when the process in question is a 32 bit process running on a 64 bit Windows system. a 32 bit process on a 32 bit system or a 64 bit process on a 64 bit system will return false, so to really get the right information about the process bitness you would first have to determine if the system itself is a 64 bit system, which incidentially one has to call  another Windows API function for. LabVIEW only returns if it is itself a 32 bit or 64 bit process, not the bitness of the underlaying OS (although if that property returns x64 then the system obviously has to be 64 bit too).

 

To determine the bitness of the OS one would have to do something along these lines:

 

Query App.TargetCPU, if that iindicates Intel x64 then it must be 64 bit Windows.

Otherwise execute with two Call Library Nodes:

 

DWORD f64 = FALSE;
IsWow64Process
(GetCurrentProcess(), &f64);

If the result in f64 us true you are running a 32 bit app on a 64 bit system, oitherwise it is a 32 bit app on a 32 bit system.

 

And yes, all the refnums returned by the various .Net nodes should be closed after use to avoid memory leaks.

Rolf Kalbermatter
My Blog
0 Kudos
Message 11 of 16
(1,270 Views)

I looked a bit more at the original snippet and there is even more wrong with it! IsWow64Process() expects a process handle, not a windows handle. So that is not likely going to work. In addition to that it seems not possible to retrieve the actual handle value from the refnum. The returned value is always 0. Not sure what is the problem here as .Net is not my domain of expertise. But it is definitely a bit more complicated than the snipped in this thread.

Rolf Kalbermatter
My Blog
0 Kudos
Message 12 of 16
(1,242 Views)

I read IsWowProcess64 a lot.

 

But I am new to Labview, so can someone please show me how to get it in my code?

0 Kudos
Message 13 of 16
(1,219 Views)

This is the code to determine if the underlaying OS is 64 bit. It does so by first checking if the LabVIEW instance is 64 bit. If this is the case it must be a 64 bit OS since 64 bit LabVIEW only runs on a 64 bit OS. Otherwise it checks if the process is running under WOW64 using your Windows API function.

 

WIN Is 64 Bit OS.png

 

Integrating this into the earlier example with all the corrections I pointed out earlier and hoisting out the IsWow64Process() call to use for determining the bitness of each enumerated process is left as an exercise. Please note that I wasn't able to get a valid process handle from the .Net nodes in that example, but I didn't try to hard, so it might be just something I did wrong. It's definitely touching Windows security limitations somehow were arbitrary processes aren't just allowed to simply query any characteristics of other processes as some of the property queries for the Process class will actually return an error to that effect.

Rolf Kalbermatter
My Blog
Message 14 of 16
(1,203 Views)

okay great, now I can see if the OS is a 64 or 32 Bit System. But how can I see if a process does?

 

code.png

0 Kudos
Message 15 of 16
(1,165 Views)

You have to use the IsWOW64Process() Call Library Node. Somehow you have to convince the .Net Nodes to return to you the numeric value of the underlaying handle for each process. Whatever I did I always got 0! The greenish wire is an object refnum not the handle itself.

 

 

It should be something along these lines:

 

Process handle.png

 

However I was not able to get a meaningfull process handle value from the .Net functions as I have already explained. Didn't try hard though as I have other work to do here.

Rolf Kalbermatter
My Blog
0 Kudos
Message 16 of 16
(1,153 Views)