How to determine Operationg System

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

How to determine Operationg System

Post by kpassaur » Thu Jul 28, 2011 8:06 am

I am trying to find a way to see if a compiled script is running on a server or not.

I have tried using %OS_SYS%, but it comes up as follows:

On Server 2003

NT.5.2.3790

On Vista

NT.6.0.6002

So both of them have NT, and version numbers, but how to tell if it is a version on a server as opposed to a workstation.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Re: How to determine Operationg System

Post by Rain » Thu Jul 28, 2011 11:06 am

systeminfo in command prompt retrieves the OS Configuration amongst other things.

Code: Select all

Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Del>%TEMP_DIR%SystemInfo.txt
Run>cmd /c systeminfo > %TEMP_DIR%SystemInfo.txt
ReadFile>%TEMP_DIR%SystemInfo.txt,System_Info
mdl>System_Info

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jul 29, 2011 9:52 pm

The info is in the Registry:

HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows NT\CurrentVersion

There are several entries that may have what you need, ProductName returns e.g. Microsoft Windows 7 Professional, there is also InstallationType which is Client on my laptop and I believe will return Server for a server OS - but I have no way to test that right now.

Okapi
Junior Coder
Posts: 28
Joined: Wed Dec 29, 2010 1:22 am

Post by Okapi » Fri Jul 29, 2011 10:39 pm

Code: Select all

VBSTART
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT ProductType FROM Win32_OperatingSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
 intProdType = objItem.ProductType 
Next
VBEND
VBEval>intProdType,intProdType

If>%intProdType%=1
MDL>Work Station
EndIf

If>{(%intProdType%=2) OR (%intProdType%=3)}
MDL>Server
EndIf

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts