Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to check windows version in batch file  (Read 3313 times)

0 Members and 1 Guest are viewing this topic.

Dan B.

  • Guest
how to check windows version in batch file
« on: April 26, 2005, 01:17:38 PM »
Hello, can someone tell me the syntax I would use in a batch file (logon script) that checks the OS version? I want to use a logon script that only performs a function on XP machines as opposed to earlier versions. Thanks!

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: how to check windows version in batch file
« Reply #1 on: April 26, 2005, 04:05:17 PM »
If your using VB Script then you can try this:

Code: [Select]
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
   Wscript.Echo objOperatingSystem.Caption & " " & _
       objOperatingSystem.Version
Next

   
If you parse objOperatingSystem.Version you can extract the info you need.
     

OR with a .bat file

Code: [Select]
@echo off
ver > dummy.txt
for /f "tokens=1-4" %%i in (dummy.txt) do (if %%k=="XP" whatever
     )
del dummy.txt


You will have to make some adjustments depending on your situation.

Hope this helps.  8)
« Last Edit: April 26, 2005, 06:39:10 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein