• 0

Check if EXE is x64?


Question

8 answers to this question

Recommended Posts

  • 0

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
Share on other sites

  • 0

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-bit

else if(IntPtr.Size == 8) // is 64-bit

Or do you want to check what architecture an external exe is, not yourself?

Link to comment
Share on other sites

  • 0

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
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.