Solved

Batch to check server OS (ignores desktop OS kernels)

Posted on 2013-06-14
3
313 Views
Last Modified: 2013-06-28
I am trying to make a batch that checks the version of the OS and if found, moves on to a part of the script.  I have two problems.  This script below works for windows xp, vista, 7...etc but not windows server OS.  
Example of what I want...
ver | find "2003" > nul
:: error 0 means found
if %ERRORLEVEL% == 0 goto Nextgen
) ELSE ( 
ver | find "2008" > nul
:: error 0 means found
if %ERRORLEVEL% == 0 goto Nextgen
) ELSE ( 
ver | find "2012" > nul
:: error 0 means found
if %ERRORLEVEL% == 0 goto Nextgen

Open in new window


if I use something more specific like the below to find server 2008, the problem is that this is also the kernel for windows 7 and I cannot have that.
VER | FINDSTR /IL "6.1." > NUL

Open in new window


Can sombody help me create a OS check that ONLY looks for windows servers 2003, 2008, and 2012?  And ignores desktop OS kernels like windows 7?

Thanks in advance
0
Comment
Question by:icecom4
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 450 total points
ID: 39248602
You can simply use a "net accounts" to find the computer role; every desktop OS since at least NT4 will show up as WORKSTATION.
The PDC (emulator) would be PRIMARY, a BDC BACKUP, and a regular server should be SERVER.
So try
@echo off
setlocal
net accounts | find /i "WORKSTATION"
if not errorlevel 1 (
	echo Workstation OS detected, leaving script ...
	goto :eof
)
REM We're on a server OS

Open in new window

0
 
LVL 13

Assisted Solution

by:rhinoceros
rhinoceros earned 50 total points
ID: 39270736
Batch File to Correctly Determine Operating System Version
http://malektips.com/xp_dos_0025.html
0
 

Author Closing Comment

by:icecom4
ID: 39285081
Thanks guys, I used oBdA's script in my production batch, but that other script seems like something I will need in the future.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question