SEMblog
Microsoft Exchange Server and
Blackberry Enterprise Server news, views and fixes.
On my technical site amset.info I have an article on how to detect the operating system in a login script.
The method that I use is to dump the results of ver out to a text file, then find the version number in those results.
Here is a code snippet based on what is on that page, for detecting Windows XP. (http://www.amset.info/loginscripts/os-id.asp)
ver >"%userprofile%"\ver.txt
Rem now find the operating system and act accordingly
findstr 5.2 "%userprofile%"\ver.txt
if errorlevel 1 goto XP
:notxp
echo not XP
goto end
:xp
echo XP
goto end
:end
echo end
When Vista was released, I decided to update the page to include Vista as an example.
I therefore added the following line:
findstr 6.0 "%userprofile%"\ver.txt
if errorlevel 1 goto Vista
However this was based on theory, and wasn't something that I had time to test before I uploaded the new page.
Needing to use it for a client who has a couple of Vista machines and part of the login script wasn't required for Vista, I tried using my own code to skip that section.
If failed to work correctly and I couldn't understand why it wouldn't skip the section I wanted, but worked for older versions of Windows.
The answer I found was in the results of the ver:
XP: Microsoft Windows XP [Version 5.1.2600]
Vista: Microsoft Windows [Version 6.0.6000]
It appears that findstr command ignores the "." in the string. So it was looking for 60 and was finding it in the XP ver results.
The solution is to change the string to search for to 6000 which results in a positive detection.
Update March 2008: With the release of Vista Sp1 the detection fails because Microsoft changed the version string, again. The updated commands required are here: http://blog.sembee.co.uk/archive/2008/03/17/74.aspx