• 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

    • True... they used the same core, but 7 worked out of the box. Vista made Me a superhero in comparison. See.. apps may have had issues running with Me because the changes were trash compared to 98SE. But I only installed Me one time and it ran, crashed.. .ran, maybe crashed some more. I made a living off of having customers reinstall Vista because it became unstable fast. Some may call 7, Vista SP3... but the final product doesn't compare to the original Vista core when they launched it. Even today, you're going to hear some that say they're still running 7, or will always have 7. Not Vista.
    • Oh man! I can't wait! 😁
    • slowness that result in unproductive, when something was easy fast one click now its basically 2 or 3 clicks and more mouse movement not the end of the world sure but forcing changes for the sake of it for no good reason its one reason why people dont like 11.
    • WhatsApp for Android expands chat themes with 18 new colors by Paul Hill The WhatsApp Beta for Android has just been updated to version 2.25.19.2 (via WABetaInfo) bringing with it 18 new color options, expanding the selection from 20 to 38 colors. This update brings the Android app up to parity with the iOS version, which got this beta update at the start of the month. The expansion of colors will give users greater personalization options for their WhatsApp chats. You can pick the new colors individually per chat or from the settings for every chat, complementing the existing support for various custom backgrounds. How the new chat themes work To set the new colors for individual chats, just open the chat you want to theme, press the three dot menu in the top right and go to themes and change the chat color. To change the theme color across the whole of the app, just go to settings and then select chats and change the chat theme. The new colors are compatible with both light and dark modes and affect the message bubbles. Unlike Messenger where theme changes can be seen by your contact, theme changes in WhatsApp are only visible to the user who applies it. User reception and future outlook Most people running WhatsApp are using the stable version, so you won’t see these new theme colors yet, we will have to wait a bit longer for that. Even if you’re on the beta, the feature may not be available yet as it’s being rolled out. While not a massive change, lots of people like to theme their WhatsApp messages so this change will be welcomed by those that do that. The messaging app scene is very competitive, so this will help Meta retain users on WhatsApp by boosting satisfaction. If you have had a chance to try out the new themes, let us know in the comments what you think!
    • Yup, that thing. Thank you. I found it invaluable for workflow.
  • Recent Achievements

    • Explorer
      Legend20 went up a rank
      Explorer
    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      618
    2. 2
      ATLien_0
      278
    3. 3
      +FloatingFatMan
      179
    4. 4
      Michael Scrip
      150
    5. 5
      Steven P.
      115
  • Tell a friend

    Love Neowin? Tell a friend!