Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: How to know the Windows OS that perl is running on

by mr_mischief (Monsignor)
on Apr 28, 2011 at 19:34 UTC ( #901857=note: print w/replies, xml ) Need Help??

in reply to How to know the Windows OS that perl is running on

There are a few answers here. They tend to be much more Windows-specific than Perl-specific, but then that means they work from any language. has a batch script which uses the ver command interpreter built-in command which will tell you the version and the processor architecture. I know a command line seems archaic to some Windows users, but it can still be useful. I'm sure you could find a way to do this without the batch file based on the information provided.

@Echo off Setlocal :: Get windows Version numbers For /f "tokens=2 delims=[]" %%G in ('ver') Do (set _version=%%G) For /f "tokens=2,3,4 delims=. " %%G in ('echo %_version%') Do (set _ma +jor=%%G& set _minor=%%H& set _build=%%I) Echo Major version: %_major% Minor Version: %_minor%.%_build% if "%_major%"=="5" goto sub5 if "%_major%"=="6" goto sub6 Echo unsupported version goto:eof :sub5 ::Winxp or 2003 if "%_minor%"=="2" goto sub_2003 Echo Windows XP [%PROCESSOR_ARCHITECTURE%] goto:eof :sub_2003 Echo Windows 2003 or XP 64 bit [%PROCESSOR_ARCHITECTURE%] goto:eof :sub6 if "%_minor%"=="1" goto sub7 Echo Windows Vista or Windows 2008 [%PROCESSOR_ARCHITECTURE%] goto:eof :sub7 Echo Windows 7 or Windows 2008 R2 [%PROCESSOR_ARCHITECTURE%] goto:eof has command lists or statement dictionaries for:

They also have other information like links to the relevant MS KB entries when those apply, a Unicode character reference, an all-JavaScript password generator, and a forum. I'm not affiliated, not even as a forum member or regular user. I do enjoy their low-bandwidth and easily read pages when I just need to look up help for a command I don't have on the system I'm using at the moment. All the stuff here that is pulled from SS64 is of course copyright SS64. The site is even Creative Commons ShareAlike (Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales), so I have a local mirror or three of the whole site for my own use.It's only 14 MB -- see what I mean about low-bandwidth? Still, of course, if you're taking more than one complete mirror mirror your first mirror to do that.

If you can figure out all you need by parsing the environment variable %PROCESSOR_ARCHITECTURE% (which says x86 or IA64) then that'll be handy, but I think that returns x86 for 32-bit applications on 64-bit OSes. But then there's the Windows-on-Windows shim, and it has its own variable... has a howto for determining if a 32-bit program is running on 64-bit Windows by using both PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432 but admits it's a bit of tickling the wizard.

There's also the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE registry key. You can even read this from a command line of:

reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Envir +onment" /v PROCESSOR_ARCHITECTURE

Then there's the Microsoft Knowledge Base article on bit width of the OS: complete with its own batch file which checks the registry a different way.

You Windows folks might want to give some love to configure and to Config so that $Config{'archname'} and $Config{'archname64'} end up being useful (if they're not now, which I assume is the case since nobody mentioned those). Having separate Win32 modules is all well and good for many things in areas in which you're trying to do complex things in ways Thompson, Kernighan, Ritchie, Pike, et al never intended. Yet I think it's not too much to ask that Perl users on Windows can tell easily what "Windows" means at the moment. Just expect the porters to not think it's too much to ask for Windows folks who care to do the work. Heck, even $^O might be made to return the information you want if you can provide the patch.

Hey, I'm a Linux guy. Who says it's hard to find relevant information using search engine? ;-) (Okay, I admit, I was an old DOS hand part of last century, and part of knowing what to search for was based on that.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://901857]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-01-20 23:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.