#1 05 Oct 2009 10:49

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Finding Os type and 32 / 64 bit

Hi all

I found a script on the net that dosent always work

@echo off
ver | find "95">nul
if not errorlevel 1 (
set WinOS=Windows 95
goto OSis)
ver | find "98">nul
if not errorlevel 1 (
set WinOS=Windows 98
goto OSis)
ver | find "Millennium">nul
if not errorlevel 1 (
set WinOS=Windows ME
goto OSis)
ver | find "NT">nul
if not errorlevel 1 (
set WinOS=Windows NT
goto OSis)
ver | find "2000">nul
if not errorlevel 1 (
set WinOS=Windows 2000
goto OSis)
ver | find "XP">nul
if not errorlevel 1 (
set WinOS=Windows XP
goto OSis)
ver | find "2003">nul
if not errorlevel 1 (
set WinOS=Windows 2003
goto OSis)
ver | find "Vista">nul
if not errorlevel 1 (
set WinOS=Windows Vista
goto OSis)
ver | find "6.1.7600">nul
if not errorlevel 1 (
set WinOS=Windows 7)
goto OSis)
:OSis
echo.
echo.
echo.Your Operating System Is %WinOS%
echo.
echo.
@pause

creds to origanal author

Its the vista and windows 7 that dont seem to work properly, i dont run vista so a friend of mine tried it and reported it didnt work properly.
On Win 7 which the script didnt include i modded it to include 7 but it dosent show the word "Seven" in ver when you run it from the cmdline so i tagged it with the release number but that will only pick up that release so it aint perfect.

So:
Is there a better way to do this?
And ideally i would like this to show 32 bit and 64 bit as well
is there a different section of windows i should be interogating other than ver?

it would be ideal if i can keep %WinOS% and %whatever the 32/64 answer is% seperate so i can reference them later in the sheet as certain software i am using requires different installs

I also found this from bluesxman

@echo off
set OSVersion=
for %%a in (XP Vista) do (
    ver | find /i "Windows %%a" >nul
    if not errorlevel 1 set OSVersion=%%a
)

if not defined OSVersion echo:Error finding OS version.&pause&goto :EOF

if "%OSVersion%" EQU "XP" (
    REM [[ YOUR XP SPECIFIC ACTIONS GO HERE ]]
)

if "%OSVersion%" EQU "Vista" (
    REM [[ YOUR VISTA SPECIFIC ACTIONS GO HERE ]]
)

and i wonder if this would be usefull, obviously it would need to work with 7 etc

EDIT: just been having a poke around
WMIC OS
and it gives detailed info about the installed os, would this be a better way to find the info i need?

The subheading in WMIC OS called
"Name" gave  Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1
which the last bit isnt usefull ie: |C:\WINDOWS|\Device\Harddisk0\Partition1

But
"Caption" gave Microsoft Windows XP Professional

"CreationClassName" gave Win32_OperatingSystem so maybe that is useable to get the info i need.

Im assuming of course that WMIC exisited in OS before XP, at the end of the day i rarely see machines that are older OS than XP so i could get away with it working on XP / Vista / Seven and ignore the older ones

Lol
Now ive found another one by *SCRIPTER*

REM Determine the processor and os "xp,vista,x64,x86" so we know what data collections we can do
    for /f "tokens=*" %%a in ('ver') do (
    set WindowsVersion=%%a
    )
    for /f "tokens=2 delims== " %%a in ('"set | find "PROCESSOR_ARCHITECTURE""') do (
    set Processor_Architecture=%%a
        )
    )
    if /i [%Processor_Architecture%]==[x86] (
    if /i "%WindowsVersion%" == "Microsoft Windows XP [Version 5.1.2600]" (
    set Processor_Architecture=WindowsXp_x86
        )
    )
    if /i [%Processor_Architecture%]==[x86] (
    if /i "%WindowsVersion%" == "Microsoft Windows [Version 6.0.6000]" (
    set Processor_Architecture=WindowsVista_x86
        )
    )
    if /i [%Processor_Architecture%]==[x86] (
    if /i "%WindowsVersion%" == "Microsoft Windows [Version 6.0.6001]" (
    set Processor_Architecture=WindowsVista_x86
        )
    )
    if /i [%Processor_Architecture%]==[AMD64] (
    if /i "%WindowsVersion%" == "Microsoft Windows XP [Version 5.1.2600]" (
    set Processor_Architecture=WindowsXp_Amd64
        )
    )
   
    echo The determined operating system is . . .
    echo %Processor_Architecture%
    echo The system will prepare data collections for . . .
    echo %Processor_Architecture%

This one dosent make a lot of sense to me and i im guessing it still uses "ver" due to the "for /f "tokens=*" %%a in ('ver') d" line
Ive been looking round for a definitive list of windows versions so i could write into the origanal one "ver | find "6.1.7600">nul" and change the numbers for each type.

anyway hopefully someone will have a browse and assist

thx for any help

Last edited by Chimaera (05 Oct 2009 13:02)

Offline

#2 05 Oct 2009 14:45

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: Finding Os type and 32 / 64 bit

I think the WMIC option you discussed is probably the way to go.

I.E.

WMIC OS GET Caption,Version /FORMAT:list

It would seem that if it's a 64bit installation, it specifically tells you; otherwise it doesn't mention the architecture.

Here's some sample output:

WinXP 32bit

Caption=Microsoft Windows XP Professional
Version=5.1.2600

Win2003 32bit

Caption=Microsoft(R) Windows(R) Server 2003, Standard Edition
Version=5.2.3790

Win2003 64bit

Caption=Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
Version=5.2.3790

EDIT: Oh hang on a minute, <expletive deleted> Win2008 doesn't play ball.

Win2008 64bit

Caption=Microsoft® Windows Server® 2008 Standard
Version=6.0.6001

Maybe you could supplement it thus:

C:\Users\administrator>wmic cpu get Caption /format:list

Caption=AMD64 Family 16 Model 4 Stepping 2

But I'm not entirely sure what it would say on a 64bit machine with 32bit Windows installed.

Last edited by bluesxman (05 Oct 2009 15:00)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#3 05 Oct 2009 19:35

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

But I'm not entirely sure what it would say on a 64bit machine with 32bit Windows installed.

It says this

Caption=x86 Family 15 Model 47 Stepping 0

Cos im running 64 hardware and 32 bit XP OS atm

Hope that helps

Bit of playing with a CMD window gave this

C:\>WMIC OS GET Caption,CreationClassName
Caption                                             CreationClassName
Microsoft Windows XP Professional  Win32_OperatingSystem

or

C:\>WMIC OS GET Caption,CreationClassName /format:list


Caption=Microsoft Windows XP Professional
CreationClassName=Win32_OperatingSystem

Last edited by Chimaera (05 Oct 2009 19:43)

Offline

#4 05 Oct 2009 21:40

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Ok small update

Ive been messing with this for a few hours and partially got this to work

@echo off
for /f %%g in ('WMIC OS GET Name') do (
    set WindowsVersion=%%g
)
echo %WindowsVersion%
@pause

Now this reports the word Microsoft but it dosent tell the rest of the sentence

Any ideas why its not reporting the whole line?

Its my first attempt at "For" so play nice

Offline

#5 05 Oct 2009 21:49

avery_larry
Member
Registered: 11 Jul 2007
Posts: 266

Re: Finding Os type and 32 / 64 bit

Chimaera wrote:

Ok small update

Ive been messing with this for a few hours and partially got this to work

@echo off
for /f %%g in ('WMIC OS GET Name') do (
    set WindowsVersion=%%g
)
echo %WindowsVersion%
@pause

Now this reports the word Microsoft but it dosent tell the rest of the sentence

Any ideas why its not reporting the whole line?

Its my first attempt at "For" so play nice

By default 'for' will only return the first "token", or the first object up until a delimiter (space).  Try this:

for /f "tokens=*" %%g in ....

That tells it to use all tokens.

Offline

#6 05 Oct 2009 21:49

avery_larry
Member
Registered: 11 Jul 2007
Posts: 266

Re: Finding Os type and 32 / 64 bit

for /f "delims=" %%g in ...

That will pretty much do the same thing.

Offline

#7 05 Oct 2009 21:50

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

thx stvsnwleppord

But it just flashes a black screen and exits

thx avery
@avery so tokens means words then?

i tried bothe ways  tokens and delims and it just flashes and exits

Last edited by Chimaera (05 Oct 2009 21:56)

Offline

#8 05 Oct 2009 22:12

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

already running with it off and when i remove the "tokens=*" it works again
odd

Offline

#9 06 Oct 2009 03:30

avery_larry
Member
Registered: 11 Jul 2007
Posts: 266

Re: Finding Os type and 32 / 64 bit

The output of the wmic command contains pipe characters --     |

This might work:

@echo off
for /f "tokens=*" %%g in ('wmic os get name') do (
   set "tmp=%%g"
)
echo %tmp:|=^|%

Offline

#10 06 Oct 2009 08:06

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

That works thx a lot
The output now is
Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1

So now i just need to reduce it to

Microsoft Windows XP Professional

and then play around with the 32/64 bit in a similar way

Thanks for all the help guys

Offline

#11 06 Oct 2009 12:51

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: Finding Os type and 32 / 64 bit

Why not just use "WMIC OS GET CAPTION", as suggested above?


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#12 06 Oct 2009 18:19

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Sorry guys i lost the plot somewhere on that one

Thx again avery_larry thats working now

and bluesxman ill try and pay attn [got carried away lol]


Ok got it working nice on XP

Then i turned my attention to Win 7

if i test

@echo off
wmic os get caption
@pause

It returns Microsoft Windows 7 Ultimate as it should

But If i use

@echo off
for /f "tokens=*" %%g in ('wmic os get caption') do (
   set "os_name=%%g"
)
echo    %os_name:|=^|%
@pause

It returns

ECHO is off.
Press any key to continue . . .

where the hell did i go wrong ?
using cmd i can see all the sections for wmic and they are the same in either OS

Hmm the plot thickens, booted the XP again and it works fine on either test so there must be something peculiar to Win 7 but its ironic that accesed directly it works with this
wmic os get caption

I ran it again with echo ON

M:\>for /F "tokens=*" %g in ('wmic os get name') do (set "tmp=%g" )

M:\>(set "tmp=Name
" )

M:\>(set "tmp=Microsoft Windows 7 Ultimate |C:\Windows|\Device\Harddisk2\Partition1
" )

" ) (set "tmp=

M:\>echo
ECHO is on.
Press any key to continue . . .

And the output from XP

O:\>for /F "tokens=*" %g in ('wmic os get name') do (set "tmp=%g" )

" ) (set "tmp=Name

" ) (set "tmp=Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1

O:\>echo Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1

Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1

Press any key to continue . . .

Last edited by Chimaera (06 Oct 2009 22:30)

Offline

#13 07 Oct 2009 10:10

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: Finding Os type and 32 / 64 bit

I think the output format is half the problem.

Try it like this:

for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get caption /format:list ^| findstr "^Caption="`) do (
    set %%a=%%b
)

echo %Caption%

Last edited by bluesxman (07 Oct 2009 10:28)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#14 07 Oct 2009 20:22

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

That works a treat bluesxman

But::
Big downside i have found with what i was planning
If the OS is older than 2003 or basic or home versions of XP/vista/ and probably seven [untested]

wmic dosent exist in those systems

:wall::wall:

Last edited by Chimaera (07 Oct 2009 20:22)

Offline

#15 10 Oct 2009 08:03

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Ok for now untill i think of another way to cover the basic systems this is the code as it stands for those that can make any use of it

@echo off
echo.
echo.
for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get Caption /format:list ^| findstr "^Caption="`) do (
    set %%a=%%b
)

for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get CreationClassName /format:list ^| findstr "^CreationClassName="`) do (
    set %%a=%%b
)

IF [%CreationClassName%]==[Win32_OperatingSystem] goto:32BIT
    set os_type=64 Bit
goto END
:32BIT
    set os_type=32 Bit

echo     %Caption% %os_type%
echo.
echo.
@pause

In time hopefully i can come up with a better way so it includes all systems rather than the newest ones roll

Offline

#16 12 Oct 2009 09:24

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: Finding Os type and 32 / 64 bit

If you run "WMIC /? >nul 2>&1" and check for errorlevel 9009 (this is returned when the executable is not found) you can then use "ver" as a fall back option for when WMIC is not installed.  Actually, I'm just realising I have these environment variables set by the system:

PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 6, GenuineIntel

... they also exist on Win2000 x86, but I don't have an  Win2000 x64 to check against -- this should help with the architecture detection effort.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#17 12 Oct 2009 09:57

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

what are they set in m8 ver or wmic?

btw do i include

IF [WMIC /? >nul 2>&1]==[errorlevel 9009] goto:OLDER

or

IF [WMIC /? >nul 2>&1]==[9009] goto:OLDER

couldnt get that working so i went this way but this is untested on older systems

Then i guess if this is proved the just need to fine tune the ver stuff at the top and it should be good to go

@echo off
echo.
IF EXIST WMIC goto:wmic_start ELSE goto:ver_start
::===========================================================
:wmic_start
for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get Caption /format:list ^| findstr "^Caption="`) do (
    set %%a=%%b
)

for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get CreationClassName /format:list ^| findstr "^CreationClassName="`) do (
    set %%a=%%b
)

IF [%CreationClassName%]==[Win32_OperatingSystem] goto:32BIT
    set os_type=64 Bit
goto END
:32BIT
    set os_type=32 Bit

echo     %Caption% %os_type%
echo.
@pause
goto:EOF
::============================================================
:ver_start
ver
echo.
goto:EOF

@pause
:EOF

Last edited by Chimaera (12 Oct 2009 11:01)

Offline

#18 12 Oct 2009 11:00

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 939

Re: Finding Os type and 32 / 64 bit

Neither, they are environment variables, you can see them if you type "set" at the command prompt.  They are interrogated in the usual fashion for environment variables -- by referring to them thus "%PROCESSOR_ARCHITECTURE%" etc.

You don't check errorlevels like that.

You need to do something like this:

WMIC /? >nul 2>&1
if %errorlevel% EQU 9009 (
    echo:WMIC not found
) ELSE (
    echo:WMIC found
)

Last edited by bluesxman (12 Oct 2009 11:00)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#19 12 Oct 2009 19:34

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Slimmed it down to this now, ill do some more testing of it tommoz at work

::variables
if %PROCESSOR_ARCHITECTURE%==x86   set pro_arch=32 Bit
if %PROCESSOR_ARCHITECTURE%==AMD64 set pro_arch=64 Bit
if %PROCESSOR_ARCHITECTURE%==IA64 set pro_arch=Itanium 64 Bit
::===========================================================
:wmic_test
WMIC /? >nul 2>&1
if %errorlevel% EQU 9009 (
    goto:ver_start
) ELSE (
    goto:wmic_start
)
::===========================================================
:wmic_start
for /f "usebackq tokens=1,* delims==" %%a in (`wmic os get Caption /format:list ^| findstr "^Caption="`) do (
    set %%a=%%b
)

echo     %Caption% %pro_arch%
echo.
@pause
goto:EOF
::============================================================
:ver_start
ver etc etc

Last edited by Chimaera (12 Oct 2009 19:36)

Offline

#20 12 Oct 2009 22:08

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 769
Website

Re: Finding Os type and 32 / 64 bit

If you can use powershell, heres the script I use for getting OS version and Service pack No's
http://ss64.com/ps/get-wmiobject-win32.html

Offline

#21 21 Oct 2009 15:44

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Unfortunatly Powershell isnt an option at this time

Its getting there but i need to do a load of work on the ver stuff to get that working properly

when i get the time anyway:rolleyes:

Offline

#22 12 May 2011 16:24

scrfix
Member
Registered: 12 May 2011
Posts: 1

Re: Finding Os type and 32 / 64 bit

I know this is an old thread however I wrote a batch script to do exactly what you are looking for on XP, Vista, 7, Server 2003 Enterprise, Server 2003 SBS, Server 2008: http://forums.techguy.org/7927375-post8.html

This may possibly work for Windows 98, Me, 2000 and 2000 Server as well.

Last edited by scrfix (13 May 2011 17:59)

Offline

#23 17 May 2011 10:38

Chimaera
Member
Registered: 24 Aug 2009
Posts: 134

Re: Finding Os type and 32 / 64 bit

Nice script

I have not done any more on this for a long while

Thanks for sharing

Chimaera

Offline

#24 05 Jun 2011 10:29

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 769
Website

Re: Finding Os type and 32 / 64 bit

Heres a simple way to detect 32/64 bitness:

IF PROCESSOR_ARCHITECTURE == x86 AND
   PROCESSOR_ARCHITEW6432 NOT DEFINED THEN
   // OS is 32bit
ELSE
   // OS is 64bit
END IF

from David Wang http://blogs.msdn.com/b/david.wang/arch … tness.aspx

Offline

#25 06 Jun 2011 08:23

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 331

Re: Finding Os type and 32 / 64 bit


http://www.facebook.com/npocmaka

Offline

#26 06 Jun 2011 18:18

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 769
Website

Re: Finding Os type and 32 / 64 bit

npocmaka wrote:

That will find the hardware, but it is possible to install a 32 bit OS onto 64 bit hardware (sometimes done to save licensing fees or to support some legacy system) so in such cases it would give misleading results.

But I could be wrong I haven't tested this.

Offline

#27 10 Jun 2011 08:27

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 331

Re: Finding Os type and 32 / 64 bit

Simon Sheppard wrote:
npocmaka wrote:

That will find the hardware, but it is possible to install a 32 bit OS onto 64 bit hardware (sometimes done to save licensing fees or to support some legacy system) so in such cases it would give misleading results.

But I could be wrong I haven't tested this.

Hmm... sounds sensible as the value is under "HARDWARE" node.
I have no XP 64 or server 2003 but in vista and win 7 64 bit versions have following address in registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
If it's available  WIN2003/XP can be used for check.


http://www.facebook.com/npocmaka

Offline

Board footer

Powered by FluxBB