Login Scripts
Operating System Detection

Sometimes you need to detect the operating system that a machine is running. This information can then be used to setup machines in different ways or to push out updates for specific operating systems. In much the same way as location can be found, the operating system can be identified.

To see a version of this script in action, please look at our "Branding your Machine with your own OEM Info" page which you can find here.

Note: Numbers in the notes correspond with the numbers down the side of the example script.

  1. First, collect the version information and dump it to a file. In this case we are using the system drive variable to set the location. This will usually be "c:\"
  2. The "findstr" command then searches the "ver.txt" file for the number which coincides with the version of Windows the script is running on. When it gets a match, it moves on to the indicated section. Otherwise it carries on down the list.
  3. If it fails then the script presumes it is a variant of Windows 9x (95, 98 or ME) and send it to that point in the script.
  4. Now for each operating system, the script does two things, before moving on to the "next" section.
    1. It creates a new variable called "OpSys" with a small label that identifies the operating system. This could be used later in the script if required.
    2. In this example login script, "echo" is used to append the new variable to a file called "result.txt" which will be found in the system drive (c:\ usually). This allows you to check whether the script is working correctly.

    Note: There are two entries for Vista, as the version code changed in a service pack. Windows 10 used 6.4 in early previews, but this has now changed to 10.x

    You will replace the second part with your own commands, which are operating system dependant.

  5. The ":next" section could be any part of your login script.
    In this example it appends "done" to the "result.txt" file created earlier in the script.
1 ver >%systemdrive%\ver.txt
2 findstr "4.0" %systemdrive%\ver.txt
if not errorlevel 1 goto nt4
findstr "5.0" %systemdrive%\ver.txt
if not errorlevel 1 goto win2k
findstr "5.1" %systemdrive%\ver.txt
if not errorlevel 1 goto winxp
findstr "5.2" %systemdrive%\ver.txt
if not errorlevel 1 goto win2003
findstr "6000" %systemdrive%\ver.txt
if not errorlevel 1 goto vista
findstr "6001" %systemdrive%\ver.txt
if not errorlevel 1 goto vista
findstr "7600" %systemdrive%\ver.txt
if not errorlevel 1 goto win7
findstr "6.2" %systemdrive%\ver.txt
if not errorlevel 1 goto win8
findstr "6.3" %systemdrive%\ver.txt
if not errorlevel 1 goto win81
findstr "10" %systemdrive%\ver.txt
if not errorlevel 1 goto win10
3 goto win9x
4

goto next

:win9x
set OpSys=9x
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 9x settings

(enter the settings for Windows 95, 98, ME)

goto next

:nt4
set OpSys-NT4
echo %OpSys% >>%systemdrive%\result.txt
rem Windows NT4 settings

(enter the settings for Windows NT 4)

goto next

:win2k
set OpSys=Win2K
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 2000 settings

(enter the settings for Windows 2000)

goto next

:winxp
set OpSys=XP
echo %OpSys% >>%systemdrive%\result.txt
rem Windows XP settings

(enter the settings for Windows XP)

goto next

:win2003
set OpSys=Win2003
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 2003 settings

(enter the settings for Windows 2003 Server)

:vista
set OpSys=WinVista
echo %OpSys% >>%systemdrive%\result.txt
rem Windows Vista settings

(enter the settings for Windows Vista)

:win7
set OpSys=Win7
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 7 settings

(enter the settings for Windows 7)

:win8
set OpSys=Win8
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 7 settings

(enter the settings for Windows 8)

:win81
set OpSys=Win81
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 7 settings

(enter the settings for Windows 8.1)

:win10
set OpSys=Win10
echo %OpSys% >>%systemdrive%\result.txt
rem Windows 7 settings

(enter the settings for Windows 10)

5 :next
echo done >>%systemdrive%\result.txt

Complete Sample - Ready to Copy and Paste.

Remember to turn off word wrap when working in notepad


Top of the Page - Home Page
Last Page Update: 28/03/2015

Copyright Sembee Ltd. 1998 - 2024.

Reproduction of any content on this web site is prohibited without express written consent. Use of this web site is subject to our terms and conditions.

All trademarks and registered trademarks are property of their respective owners. This site is not endorsed or recommended by any company or organisation mentioned within and is to provide guidance only and as such we cannot be held responsible for any consequences of following the advice given.

Sembee Ltd. is registered in England and Wales at 1 Carnegie Road, Newbury, Berkshire, RG14 5DJ.
Registered company number: 4704428. VAT Number GB 904 5603 43.

Server 1