fhpuqrgrpgvirzhpujbj Posted February 7, 2009 Share Posted February 7, 2009 How can I check if an EXE is 64 bit with code? Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/ Share on other sites More sharing options...
0 simsie Posted February 7, 2009 Share Posted February 7, 2009 If you're coding in vb.net I believe it will be 32-bit on 32-bit systems and 64-bit on 64-bit systems. With that said run it on an x64 system and look at the processes tab in Task Manager. If your exe has *32 next to it then it's NOT 64-bit. Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590543778 Share on other sites More sharing options...
0 fhpuqrgrpgvirzhpujbj Posted February 7, 2009 Author Share Posted February 7, 2009 I need a programmatic solution to check it as the user is the one that chooses the exe. I'm drawing a blank on how to do it, though. Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590543786 Share on other sites More sharing options...
0 Mike Posted February 7, 2009 Share Posted February 7, 2009 Use IntPtr.Size and if it returns 4 then it's 32bit, or 8 for 64-bit. Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590543802 Share on other sites More sharing options...
0 hdood Posted February 7, 2009 Share Posted February 7, 2009 Presumably he wants to know so he can load the correct non-platform neutral code. The simplest way to do it is this: if(IntPtr.Size == 4) // is 32-bitelse if(IntPtr.Size == 8) // is 64-bit Or do you want to check what architecture an external exe is, not yourself? Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590543806 Share on other sites More sharing options...
0 fhpuqrgrpgvirzhpujbj Posted February 7, 2009 Author Share Posted February 7, 2009 I want to check an external exe. Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590543832 Share on other sites More sharing options...
0 Mike Posted February 7, 2009 Share Posted February 7, 2009 have a look at http://msdn.microsoft.com/en-us/library/aa364819(VS.85).aspx Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590544076 Share on other sites More sharing options...
0 hdood Posted February 7, 2009 Share Posted February 7, 2009 Okay, in that case the only real way I can think of is by loading the file and analyzing its header. I've put together a basic example (minus error checking) that is all-managed: private void button1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); Stream fs = openFileDialog1.OpenFile(); BinaryReader br = new BinaryReader(fs); UInt16 mz = br.ReadUInt16(); if (mz == 0x5a4d) // check if it's a valid image ("MZ") { fs.Position = 60; // this location contains the offset for the PE header UInt32 peoffset = br.ReadUInt32(); fs.Position = peoffset + 4; // contains the architecture UInt16 machine = br.ReadUInt16(); if (machine == 0x8664) // IMAGE_FILE_MACHINE_AMD64 textBox1.Text = "AMD64"; else if (machine == 0x014c) // IMAGE_FILE_MACHINE_I386 textBox1.Text = "i386"; else if (machine == 0x0200) // IMAGE_FILE_MACHINE_IA64 textBox1.Text = "IA64"; else textBox1.Text = "Unknown"; } else textBox1.Text = "Invalid image"; br.Close(); } Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590544108 Share on other sites More sharing options...
0 fhpuqrgrpgvirzhpujbj Posted February 7, 2009 Author Share Posted February 7, 2009 Ah thanks much hdood. That works great. :) Link to comment https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/#findComment-590544400 Share on other sites More sharing options...
Question
fhpuqrgrpgvirzhpujbj
How can I check if an EXE is 64 bit with code?
Link to comment
https://www.neowin.net/forum/topic/732648-check-if-exe-is-x64/Share on other sites
8 answers to this question
Recommended Posts