' (c) Microsoft Corporation 1997-2003
'
'
' File Name:	SMS Excel.vbs
' Version:	1.0
'
' Release History
' 0001	-	Original	June 30, 2003

// Basic Wbem object identificators
//
var objLocator, objService, objEnumerator, objInstance;
var e = new Error();

// Query specific objects
var objSMS_R_System, objP;

// Query string
// Put SMS your query here. It should be the normal SMS query.
// This query, for example, queries all machines running MS Office

var strQuery = "select distinct p.ProductName, p.ProductVersion, SMS_R_System.Name, SMS_R_System.OperatingSystemNameandVersion, SMS_R_System.ResourceDomainORWorkgroup from SMS_R_System inner join SMS_G_System_SoftwareProduct as p on p.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_SoftwareFile as u on u.ResourceID = SMS_R_System.ResourceId where p.ProductName like '%Microsoft Office%' and p.ProductName not like '%Office Binder%' and u.FileName = 'MSOFFICE.EXE' and u.ProductId = p.ProductId order by p.ProductVersion DESC, SMS_R_System.Name";

var intIndex = 1;

objLocator = new ActiveXObject("WbemScripting.SWbemLocator");
var objXL = WScript.CreateObject("Excel.Application");

objXL.Visible = true;

objXL.WorkBooks.Add;

try {
objService = objLocator.ConnectServer("SMSSERVER","root\\SMS\\site_XXX");
};

catch (e)
{
WScript.Echo("Error: Can't connect to server")
WScript.Quit(0);
};

objService.Security_.impersonationlevel = 3;

objEnumerator = new Enumerator(objService.ExecQuery(strQuery));
for (;!objEnumerator.atEnd();objEnumerator.moveNext()) {
objInstance = objEnumerator.item();
objSMS_R_System = objInstance.SMS_R_System;
objP = objInstance.p; 

objXL.Cells(intIndex, 1).Value = strDomain;
intIndex++;
objXL.Cells(intIndex, 1).Select;
};


WScript.Echo("Script successfuly finished, no errors detected!");
WScript.Quit(0);

