• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accurately detecting 64 bit Windows architecture

 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on this for probably a month now... Basically I can get the Windows version and Service pack level, but the bit isn't accurately determined. The bit is always returned as the bit of the JRE that the code is running on (usually the 32 bit JRE is running, even on 64 bit sytems). Can anyone tell me a way to find the bit of the actual OS that is running, not just the JRE? Or even point me in the right direction? I tried doing this in C and C++, but it's just so complicated that it's not really worth my time to figure it out... Maybe I can just check if there's a folder called "Program Files (x86)" or some roundabout trick like that... it just seems like Microsoft should have made a way to check this without extensive coding in C or C++. Thanks for any help.
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This must be a bug in java... why else would os.name and os.patch.level return the actual OS attributes? os.arch only returns the JVM architecture (so how can they call this os.arch?). Anyway, I found a way around this, but so far it's somewhat of a messy solution. I created a C# program that solely runs and then returns the exit code of the architecture (either 32 or 64). This so far has been accurate. Then I just run that bit.exe file from java and read the return code to determine the real arch of the OS. The problem is that it's difficult (for me at least) to run that bit.exe from within the jar file, requiring me to now have the jar file and the exe file alongside one another to properly use my application. I'd rather have a simple java app and move on with my life, but it looks like java isn't really equipped for that yet (again, it doesn't make sense to me, but I'll have to live with it until they improve their OS details features). Anyway, here's my java code so far if anyone is interested (and so you know I'm not just asking for answers, I'm still making progress):

 
Joshua Barrett
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May I see your C# code just to satisfy my curiosity.

Have you heard or possibly considered JNI (Java Native Interface). I had to dabble with it in the past to access a bluetooth device or more specifically the HID list.

http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the C# code (I got the idea from someone on the internet):


I looked into JNI a while back, but I don't remember what I found. I guess I should check into it again when I get some more time. Thanks for the suggestion.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the following would do the same, in C:
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response. Well that will print the size of a pointer to void. Maybe if we got the size of an int... But then we still need to see if it's 4 or 8 bytes and then print (or return) either 32 or 64 respectively. That actually might be pretty helpful to me though because to run any code generated in C# you have to first install the dot net framework (which for me defeats the purpose of this project because you then have to determine if you should install the 32 bit framework out the 64 bit framework...). So I'll definitely try that out, because I think it will work.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A pointer will have the same size, regardless if it is to an int, long or anything else.

If I changed "void *" with "long long" it printed 8. If I replaced that to "long long *" it was 4 again.
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. So it looks like possibly the pointer size is 4 on a 32 bit system, and 8 on a 64 bit system. I'll have to try it out later today. Thanks for the feedback.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 32-bit architecture, Memory has 2^32 addresses... Pointer, in order to refer to the memory location, needs 32 bits (or) 4 bytes to store the memory addresses... For 64-bit, pointer needs 8 bytes...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic