Below is a code example using javascript with WMI.
More examples can be found at:
http://www.planetmps.com/
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var mystr = new String("");
var mysink;
var x=0;
function Sink_OnObjectReady(objsbemObject, objWbemContext
{
var objset = objWbemObject.Instances_();
var objEnum = new Enumerator(objset);
var enumItems = new Enumerator(objs);
for (; !enumItems.atEnd(); enumItems.moveNext())
{
var obj = enumItems.item();
var propset = obj.Properties_
var propEnum = new Enumerator(propset);
for (; !propEnum.atEnd(); propEnum.moveNext())
{
if (prop.Value != null)
{
if (prop.IsArray == true)
{
mystr = mystr + prop.Name + ": " + (prop.Value.toArray()).join(",") + "\n";
}
else
{
if (prop.CIMType == 101)
{
mystr = mystr + prop.Name + ": " + WMIDateStringToDate(prop.Value) + "\n";
}
else
{
mystr = mystr + prop.Name + ": " + prop.Value + "\n";
}
}
}
}
WScript.Echo(mystr);
mystr = "";
break;
}
x=1;
}
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.connectServer('.', "root\\CIMV2\\ms_409");
mysink = WScript.CreateObject("WbemScripting.SWbemSink");
service.GetAsync(mysink, "Win32_Service");
while(x == 0)
{
WScript.Sleep(1000);
}
function WMIDateStringToDate(dtmDate)
{
if (dtmDate == null)
{
return "null date";
}
var strDateTime;
if (dtmDate.substr(4, 1) == 0)
{
strDateTime = dtmDate.substr(5, 1) + "/";
}
else
{
strDateTime = dtmDate.substr(4, 2) + "/";
}
if (dtmDate.substr(6, 1) == 0)
{
strDateTime = strDateTime + dtmDate.substr(7, 1) + "/";
}
else
{
strDateTime = strDateTime + dtmDate.substr(6, 2) + "/";
}
strDateTime = strDateTime + dtmDate.substr(0, 4) + " " +
dtmDate.substr(8, 2) + ":" +
dtmDate.substr(10, 2) + ":" +
dtmDate.substr(12, 2);
return(strDateTime);
}
No comments:
Post a Comment