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
Highlighted

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
Averna BV
0 Kudos
Message 11 of 16
(601 Views)
Highlighted

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
Averna BV
0 Kudos
Message 12 of 16
(573 Views)
Highlighted

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
(550 Views)
Highlighted

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
Averna BV
Message 14 of 16
(534 Views)
Highlighted

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
(496 Views)
Highlighted

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
Averna BV
0 Kudos
Message 16 of 16
(484 Views)