• 0

Programmatically determine whether Windows is 32 or 64 bit.


Question

I am trying to write a launcher that will call up the appropriate installer for a user's system. I am aware of how to determine what verison of Windows such as 2k, XP, Vista, etc. but I am having trouble figuring out how to determine programmatically whether the installed OS is 32 or 64 bit. I would like to do it from the command prompt if possible but any language that would not require me to pre-install libraries on the users computer would also work. Any help would be appreciated.

13 answers to this question

Recommended Posts

  • 0
  lunamonkey said:

These methods only work on Vista and XP SP2, I need the program to function fully on any version of windows from 2000 to present.

  • 0

Yes, we have to know the language to answer the question.

The environment variable PROCESSOR_ARCHITECTURE will be either AMD64 or x86 (which can again have PROCESSOR_ARCHITEW6432 set if the 32-bit program is actually running on a 64-bit OS), but I don't know if that counts as "programatically."

In managed code you can just check the size of IntPtr. It will be 4 for 32-bit and 8 for 64-bit.

  • 0

Guess I need to add a little more context to this post.

I am building a CD with an autorun. The software publisher has 2 seperate installers for 64 and 32 bit environments. I am looking to have a very simple (hopefully batch) application that will determine which installer to use on the given system. I am willing to use a 3rd party utility as long as it is released free and the publisher does not mind redistribution.

  • 0

I don't see why they can't do it themselves? It's just a few lines of C code, compiled as a 32-bit program.

typedef BOOL (WINAPI *IW64PFP)(HANDLE, BOOL *);

BOOL is64bit()
{
	BOOL res = FALSE;
	IW64PFP  IW64P = (IW64PFP)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");

	if(IW64P != NULL)
	{
		IW64P(GetCurrentProcess(), &res);
	}

	return res;
}

Then just do whatever you want depending on the result. Also, remember to sign the program with a digital certificate.

If you really want it to just be a batch file though, something like this would work:

@echo off
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
	@start 32bitinstaller.exe
) else (
	if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
		@start 64bitinstaller.exe
	) else (
		echo Unsupported platform.
		@pause
	)
)
@exit

Edited by hdood
  • 0

hdhood's batch file example should be perfect for what you clarified you want to do. :)

@ Lannister: .NET apps are generally generated at runtime or at install-time with NGEN so one installer can create native apps for both architectures.

  • 0

Thanks hdood. Your batch example was exactly what I needed. Coupled with ver to ensure that the operating system is one of the supported oses for the app I have everything I need. Thanks for everyones prompt responses.

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

    • No registered users viewing this page.
  • Posts

    • I guess companies have numbers that don't necessarily match your assessment.
    • I agree that all capabilities of the card should be reviewed, but there is a very important difference between reviewing what multiframe generation is and does for you, and simply claiming a card has 200+ FPS just because MFG is on. You are probably well aware that frame generation is getting a lot of hate, which I feel like is partly unfair to it. However, Nvidia has used frame generation to tell outright lies about their products, most notably claiming that a 5070 is as powerful as a 4090. Its easy to hate something when it is being used to make dishonest statements like that. I'm not a big fan of the popular term "fake frames" just because I feel like it is overly negative, but I do think it is important to make some kind of distinction between game engine frames and filler frames.
    • What is the replacement or successor to it right now?
    • iPhone 17 Pro Max could have the biggest battery ever on an iPhone by Devesh Beri Leaks around how the iPhone 17 Pro lineup is going to look may have left fans hesitant about what Apple is planning for its next flagship, but not every rumor paints a gloomy picture. In fact, one area where the iPhone 17 Pro Max could truly stand out is its battery; rumors say it is to have the biggest battery ever seen in an iPhone. Let's be honest, battery life has long been a weak point for iPhones. No matter how efficient Apple's A-series chipsets are said to be, users often find their devices running out of juice quicker than expected. Much of the blame could be put on the relatively small battery sizes Apple has chosen over the years, especially when compared to the competition. Many rival brands now give their large-screen devices, those with displays bigger than 6.5 inches, batteries of at least 5000mAh. In contrast, Apple's largest iPhones have lagged behind in this department, with the iPhone 16 Pro Max coming in at 4676mAh. It seems like it is set to change with the iPhone 17 Pro Max, as a prominent leaker, Instant Digital, revealed that the battery of the iPhone 17 Pro Max will finally reach the 5000mAh mark. How big a change would it be? To put it in perspective, the iPhone 17 Pro Max's battery would be about 6.9% bigger than the iPhone 16 Pro Max, 13.1% more than the iPhone 15 Pro Max, and 15.7% more than the iPhone 14 Pro Max. If these rumors are accurate, the iPhone 17 Pro Max may finally address one of the most common complaints about Apple's flagship devices, but then again, Apple would still be lagging as most of the brands, specially the Chinese ones have already moved to the battery limits of 6000mAh and some have even touched 7000mAh. This rumor comes after the observation that Apple's struggles with AI may prompt it to transition Siri to either OpenAI or Anthropic's AI capabilities. Image source: Digit.in
  • Recent Achievements

    • Week One Done
      Devesh Beri earned a badge
      Week One Done
    • Week One Done
      956400 earned a badge
      Week One Done
    • First Post
      loose_observer earned a badge
      First Post
    • Week One Done
      BeeJay_Balu earned a badge
      Week One Done
    • Week One Done
      filminutz earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      465
    2. 2
      ATLien_0
      159
    3. 3
      +FloatingFatMan
      149
    4. 4
      Nick H.
      66
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!