October 13, 200718 yr Hi !Is it possible to check for the installed Windows version in a small cmd script ? I would like to check if the OS is either Windows Server 2003, Windows XP, Windows 2000 or Windows Vista.However the variable "OS" is returning Windows_NT in all 3 cases. Any ideas ?Thanks for your help !Alex
October 13, 200718 yr Try this VBS scriptSave As OsName.vbsstrComputer = "." Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) For Each objItem in colItems msgbox "Os Name: " & objItem.Caption & " - " & objItem.Version,4128,"Os Name" Next Edited October 13, 200718 yr by gunsmokingman
October 13, 200718 yr Author Hi gunsmokingman !You are great (as usual!) Thanks !Just two more questions ... 1. since I am not good in vbs ... how can I add the OS Name into a variable from inside the vbs and use that variable in a cmd ? (I would start the vbs from inside that cmd)2. Would it be possible to just strip the output to XP, Vista, 2003 or 2000 for the 4 major OSes and not have all the subversions (like Home, Standard, build numbers etc.) in the name ? Thats because I would simply like to do different stuff for Vista than for XP/2000/2003 so I just need to know if the OS is Vista or XP or 2000/2003.Thanks for your help !Alex
October 13, 200718 yr Will this do what you want?@echo off&setlocalfor /f "delims=" %%? in ('net config work^|findstr/b Soft') do call :OSis %%?echo/%%WinOS%% is %WinOS%endlocal&goto :eof:OSisecho/%*|find "2000">nul 2>&1&&(set "WinOS=2000"&goto :eof)echo/%*|find "2002">nul 2>&1&&(set "WinOS=XP"&goto :eof)echo/%*|find "2003">nul 2>&1&&(set "WinOS=2003"&goto :eof)echo/%*|find "Vista">nul 2>&1&&(set "WinOS=Vista"&goto :eof)
October 14, 200718 yr Here is the VBS script inside of the cmd it passes the OS Name back to theoriginal cmd.Save as OsName.cmd@Echo OffCLSColor F3Mode 55,5Title TimeMkDir %SystemDrive%\OsTempSet VBS=%SystemDrive%\OsTemp\OsName.vbsSet Cmd=%SystemDrive%\OsTemp\Name.cmd> %VBS% Echo Dim TS >> %VBS% Echo strComputer = "." >> %VBS% Echo Set Wmi = GetObject("winmgmts:\\" ^& strComputer ^& "\root\CIMV2") >> %VBS% Echo Set colItems = Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) >> %VBS% Echo Dim Name>> %VBS% Echo For Each objItem in colItems :Name=objItem.Caption :Next>> %VBS% Echo If InStr(Name,"Vista") Then Name = "Vista">> %VBS% Echo If InStr(Name,"2003") Then Name="Server 2003">> %VBS% Echo If InStr(Name,"XP") Then Name="XP">> %VBS% Echo If InStr(Name,"2000") Then Name="Windows 2000">> %VBS% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")>> %VBS% Echo Set Ts = Fso.CreateTextFile("%Cmd%")>> %VBS% Echo Ts.writeline "Set Name=" ^& Name '/-^> Varible For Name>> %VBS% Echo Ts.Close%VBS%call %Cmd%Del %VBS%Del %Cmd%RmDir %SystemDrive%\OsTempEcho.Echo -^> %Name%Echo.pause Edited October 14, 200718 yr by gunsmokingman
October 14, 200718 yr Author You are good and so very helpful !Thanks a lot, gunsmokingman !PS: The first cmd has a little error: endlocal&goto :eof should beendlocal&goto :OSisThanks so much !Bye,Alex Edited October 14, 200718 yr by Yzöwl blasphemous remark removed!
October 14, 200718 yr PS: The first cmd has a little error: endlocal&goto :eof should beendlocal&goto :OSisThere's only one person who's made a little error there, and it's certainly not me!If you can guarantee that the command interpreter, (command.com / cmd.exe), is the original one for the said OS then use ther built in ver command.@echo offver | find "95">nulif not errorlevel 1 ( set WinOS=95 goto OSis)ver | find "98">nulif not errorlevel 1 ( set WinOS=98 goto OSis)ver | find "Millennium">nulif not errorlevel 1 ( set WinOS=ME goto OSis)ver | find "NT">nulif not errorlevel 1 ( set WinOS=NT goto OSis)ver | find "2000">nulif not errorlevel 1 ( set WinOS=2000 goto OSis)ver | find "XP">nulif not errorlevel 1 ( set WinOS=XP goto OSis)ver | find "2003">nulif not errorlevel 1 ( set WinOS=2003 goto OSis)ver | find "Vista">nul if not errorlevel 1 ( set WinOS=Vista):OSisecho.Your OS is %WinOS%
October 15, 200718 yr Author HI !There's only one person who's made a little error there, and it's certainly not me!I did not mean any disrespect ! The script just did not work here, after I changedendlocal&goto :eofto endlocal&goto :OSisit did.But anyway, you gave me lots of options to solve the problem so Thanks again !
October 15, 200718 yr I didn't see it a disrespectful...just incorrect!The last line of the batch file isendlocal&goto :eofThe piece of code within/below the OSis label has already been run from the call to it earlier within the 'for in do' command.
October 15, 200718 yr The piece of code within/below the OSis label has already been run from the call to it earlier within the 'for in do' command.Maybe the problem relies in a nationalized version of the OS midiboy is running.Your small batch does not work on my system (italian) because of the "findstr/b Soft", changing it to "findstr/i Soft" works, as instead of "Software version" the output of the command contains "Versione del software", and thus the CALL to :OSis is never made. jaclaz
October 15, 200718 yr Thanks for the information, jaclaz.It's sometimes difficult to remember that although the forum is English speaking, our OSes aren't necessarily so.(especially when the originator appears to use perfect English and doesn't state their origin/language in their profile!)@echo off&setlocalfor /f "delims=" %%? in ('net config work^|findstr/i "\<soft"') do call :OSis %%?echo/%%WinOS%% is %WinOS%endlocal&goto :eof:OSisecho/%*|find "2000">nul 2>&1&&(set "WinOS=2000"&goto :eof)echo/%*|find "2002">nul 2>&1&&(set "WinOS=XP"&goto :eof)echo/%*|find "2003">nul 2>&1&&(set "WinOS=2003"&goto :eof)echo/%*|find "Vista">nul 2>&1&&(set "WinOS=Vista"&goto :eof)
October 16, 200718 yr Author Hi gunsmokingman !(especially when the originator appears to use perfect English and doesn't state their origin/language in their profile!)Thanks for the compliment (spent some time in the USA once ) and I have updated the profile !And sorry for drawing the wrong conclusions!Have a nice day !Alex
October 23, 200718 yr Author Hi again,here´s a followup question: Is there a way to test if the OS is 32 or 64 bit too ? At least with the net config command it does not seem to be possible ?Thanks again !Alex
October 23, 200718 yr If it was for Vista then it would easy. Windows Server 2003, Windows 2000, Windows NT 4.0, Windows XP, and Windows Me/98/95. This property is not available.Example for Vista onlystrComputer = "." Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) For Each objItem in colItems msgbox "OS Architecture: " & objItem.OSArchitecture,4128,"OS Architecture" NextThere is a possible way of seeing if it running in 32 or 64 using the Processor class.This displayed that my OS is running the CPU in 32 bit and shows I have a 64 bit cpu.StrComputer="."Set Wmi = GetObject("winmgmts:\\" & StrComputer & "\root\CIMV2") Set colItems = Wmi.ExecQuery("SELECT * FROM Win32_Processor",,48)Dim CpuArchitecture For Each objItem in colItems If objItem.Architecture = 0 Then CpuArchitecture = "x86" If objItem.Architecture = 1 Then CpuArchitecture = "MIPS" If objItem.Architecture = 2 Then CpuArchitecture = "Alpha" If objItem.Architecture = 3 Then CpuArchitecture = "PowerPC" If objItem.Architecture = 6 Then CpuArchitecture = "Intel Itanium Processor Family (IPF)" If objItem.Architecture = 9 Then CpuArchitecture = "x64" MsgBox "Address Width " & vbTab & objItem.AddressWidth & vbCrLf &_ "Cpu Architecture" & vbTab & CpuArchitecture,4128,"OS Architecture" Next
Create an account or sign in to comment