midiboy Posted October 13, 2007 Posted October 13, 2007 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
gunsmokingman Posted October 13, 2007 Posted October 13, 2007 (edited) 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, 2007 by gunsmokingman
midiboy Posted October 13, 2007 Author Posted October 13, 2007 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
Yzöwl Posted October 13, 2007 Posted October 13, 2007 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)
gunsmokingman Posted October 14, 2007 Posted October 14, 2007 (edited) 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, 2007 by gunsmokingman
midiboy Posted October 14, 2007 Author Posted October 14, 2007 (edited) 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, 2007 by Yzöwl blasphemous remark removed!
Yzöwl Posted October 14, 2007 Posted October 14, 2007 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%
midiboy Posted October 15, 2007 Author Posted October 15, 2007 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 !
Yzöwl Posted October 15, 2007 Posted October 15, 2007 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.
jaclaz Posted October 15, 2007 Posted October 15, 2007 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
Yzöwl Posted October 15, 2007 Posted October 15, 2007 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)
jaclaz Posted October 16, 2007 Posted October 16, 2007 Just as a confirmation:findstr/i "\<soft"works in Italian. jaclaz
midiboy Posted October 16, 2007 Author Posted October 16, 2007 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
midiboy Posted October 23, 2007 Author Posted October 23, 2007 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
gunsmokingman Posted October 23, 2007 Posted October 23, 2007 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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now