|
|
Page Last Updated: 21/02/2010 Operating System Detection
|
This information was originally on our community
site amset.info, and you may have been
redirected to this site by following a link to a URL
on that domain. This is the same information, from
the same source, just in a new location.
|
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.
- 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:\"
- 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.
- 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.
- Now for each operating system, the script does two things, before moving on to the "next" section.
- 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.
- 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.
You will replace the second part with your own commands, which are operating system dependant.
- 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 |
| 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) |
| 5 |
:next echo done >>%systemdrive%\result.txt |
Complete Sample - Ready to Copy and Paste.
Remember to turn off word wrap when working in notepad
About this site
This information originally started life as a page on amset.info, our community assistance site. However that site is targeted at Microsoft Exchange server, as Sembee Ltd. is a Microsoft Exchange consultancy. Therefore it was moved to its own domain in early 2010. Traffic from amset.info is directed here.
Other sites that are owned and operated by Sembee Ltd include kbsearch.info, certificatesforexchange.com, dosprompt.info, office-recovery.info, wuauclt.info, blog.sembee.co.uk, exbpa.com and amset.info.
|