WMI Read OS Information
OSReport( "localhost" );
function OSReport( host )
{
try
{
var query = "Select * From Win32_OperatingSystem";
var WbemLocator = new ActiveXObject( "WbemScripting.SWbemLocator");
var WbemService = WbemLocator.ConnectServer( host );
print( checkReturn( WbemService ) );
var WbemEnum = WbemService.ExecQuery( query );
var e = new Enumerator( WbemEnum );
for( ; !e.atEnd(); e.moveNext() )
{
var os = e.item();
var ostype = String( os.Name ).split( "|" );
print( "OS: .......... " + ostype[0] );
print( "Build: ....... " + os.BuildNumber );
print( "Serial Num: .. " + os.SerialNumber );
print( "Suite: ....... " + os.ProductSuite );
print( "Users [Num] .. " + os.NumberOfUsers );
print( "Last Boot: ... " + Date( os.LastBootUpTime ).toLocaleString() );
print( "Install Date:. " + Date( os.InstallDate ).toLocaleString() );
}
}
catch( e )
{
print( "Error: " + e.description );
}
}
function print( msg )
{
WScript.Echo( msg );
}
function checkReturn( code )
{
var msg = String();
var wbemErrAccessDenied = 0x80041003;
var wbemErrFailed = 0x80041001;
var wbemErrInvalidNamespace = 0x8004100E;
var wbemErrInvalidParameter = 0x80041008;
var wbemErrOutOfMemory = 0x80041006;
var wbemErrTransportFailure = 0x80041015;
switch( code )
{
case wbemErrAccessDenied:
msg = "The current or specified user name and password were not valid or authorized to make the connection.";
break;
case wbemErrFailed:
msg = "Unspecified error.";
break;
case wbemErrInvalidNamespace:
msg = "The specified namespace did not exist on the server.";
break;
case wbemErrInvalidParameter:
msg = "An invalid parameter was specified, or the namespace could not be parsed.";
break;
case wbemErrOutOfMemory:
msg = "Not enough memory to complete the operation.";
break;
case wbemErrTransportFailure:
msg = "A networking error occurred, preventing normal operation.";
break;
default:
msg = "Connected: " + code;
}
print( msg );
}