views:

381

answers:

1

I have to maintain a server-side script written in JScript (NOT Javascript) that needs to discover the OS of the system that it's running on. How can I do this correctly and robustly?

+2  A: 

Take a look here for all the different system information you can get.

Here's some sample code that I threw together based on that webpage:

var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL",
                                      wbemFlagReturnImmediately | wbemFlagForwardOnly);

var enumItems = new Enumerator(colItems);
var objItem = enumItems.item();
WScript.Echo("Caption: " + objItem.Caption);
Sean