• 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 think you need to adjust your style of approach. While some were affected by performance issues, and it's not a huge gap... you're acting as if Ryzen couldn't handle 11 at all. Performance issues are purely based on some facts in certain scenarios, while others are not. I see one link with a handful of people discussing the topic. I didn't join those topics or seek them out myself, as I didn't encounter noticeable drops in performance going from 10 to 11. It might also have to be because I don't have my nose stuck up the butt of single digit percentage points. I don't benchmark my PC every time something new comes out. Single percentage point differences in performance only ruffle the feathers of those that don't care about daily use. If you have a race car, do you compare that to your daily driver? Do you expect your Honda Accord to break the 9 second quarter mile like your 1000HP Pontiac Firebird? If you're so worried about FPS instead of enjoying your games... perhaps opening a curtain in your basement might provide a new perspective in life.
    • Currently updating my Win10 IoT Enterprise LTSC 2021 in a VM (QEMU/KVM) on Linux. but damn, updates take forever (makes me appreciate the lightness on Linux all the more). to give you a general idea... this update finished at 37 minutes into system uptime and I would estimate updates have been running roughly 20-30 minutes (some of this would be download time, but even subtracting that I would guess that 20-30min is close). granted, I only got two cores of my four core CPU (i5-3550) dedicated to the VM. but still, Linux wipes the floor with Windows in this regard.
    • It's disgusting that this exists and is being marketed by Neowin as a way to earn passive income. Support real writers and real arts. The world needs them more than ever. After at least 10 years, Neowin can GTFO my favorites bar.
    • It doesn't have to be "interesting" for a script/bot to just copy everything it finds and rehost it on another site. I hope you remember your post when AGI replaces not only your job and your career, but you entirely in the workforce...
  • Recent Achievements

    • Reacting Well
      rshit earned a badge
      Reacting Well
    • Reacting Well
      Alan- earned a badge
      Reacting Well
    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      531
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      211
    4. 4
      +Edouard
      202
    5. 5
      snowy owl
      140
  • Tell a friend

    Love Neowin? Tell a friend!