Export (0) Print
Expand All

SWbemLastError object

The methods and properties of the SWbemLastError object contain and manipulate error objects. The methods and properties of this object are exactly the same as those of the SWbemObject object, but are used to contain error information instead of WMI class information. This object can be created by the VBScript CreateObject call.

You can create an SWbemLastError error object to inspect the extended error information that is associated with a previous method call. If error information is not available, an attempt to create an error object will fail. If the call succeeds and an error object returns, the status of the object is reset. Further attempts to retrieve an error object will fail until a new error occurs. If you make an asynchronous call that fails, an SWbemLastError object may be returned to you by the SWbemSink.OnCompleted event in the objWbemErrorObject parameter.

Members

The SWbemLastError object has these types of members:

Methods

The SWbemLastError object has these methods.

MethodDescription
Associators_

Not used. The SWbemObject object provides the same method.

AssociatorsAsync_

Not used. The SWbemObject object provides the same method.

Clone_

Makes a copy of the current object.

CompareTo_

Tests two objects for equality.

Delete_

Not used. The SWbemObject object provides the same method.

DeleteAsync_

Not used. The SWbemObject object provides the same method.

ExecMethod_

Not used. The SWbemObject object provides the same method.

ExecMethodAsync_

Not used. The SWbemObject object provides the same method.

GetObjectText_

Retrieves the textual representation of the object written with MOF syntax.

Instances_

Not used. The SWbemObject object provides the same method.

InstancesAsync_

Not used. The SWbemObject object provides the same method.

Put_

Not used. The SWbemObject object provides the same method.

PutAsync_

Not used. The SWbemObject object provides the same method.

References_

Not used. The SWbemObject object provides the same method.

ReferencesAsync_

Not used. The SWbemObject object provides the same method.

SpawnDerivedClass_

Not used. The SWbemObject object provides the same method.

SpawnInstance_

Not used. The SWbemObject object provides the same method.

Subclasses_

Not used. The SWbemObject object provides the same method.

SubclassesAsync_

Not used. The SWbemObject object provides the same method.

 

Properties

The SWbemLastError object has these properties.

PropertyAccess typeDescription

Derivation_

Read-only

Not used. The SWbemObject object provides the same method.

Methods_

Read-only

Not used. The SWbemObject object provides the same method.

Path_

Read-only

Contains an SWbemObjectPath object that represents the object path of the current class or instance.

Properties_

Read-only

Represents the collection of properties of the SWbemLastError object. This property is an SWbemPropertySet object.

Qualifiers_

Read-only

Not used. The SWbemObject object provides the same method.

Security_

Read-only

Not used. The SWbemObject object provides the same method.

 

Examples

The following VBScript sample demonstrates how to inspect error and error object information.


On Error Resume Next

'Ask for non-existent class to force error

Set t_Service = GetObject("winmgmts://./root/default")
Set t_Object = t_Service.Get("Nosuchclass000")

if Err = 0 Then
 WScript.Echo "Got a class"
Else
 WScript.Echo ""
 WScript.Echo "Err Information:"
 WScript.Echo ""
 WScript.Echo "  Source:", Err.Source
 WScript.Echo "  Description:", Err.Description
 WScript.Echo "  Number", "0x" & Hex(Err.Number)

 'Create the last error object
 set t_Object = CreateObject("WbemScripting.SWbemLastError")
 WScript.Echo ""
 WScript.Echo "WMI Last Error Information:"
 WScript.Echo ""
 WScript.Echo " Operation:", t_Object.Operation
 WScript.Echo " Provider:", t_Object.ProviderName

 strDescr = t_Object.Description
 strPInfo = t_Object.ParameterInfo
 strCode = t_Object.StatusCode

 if (strDescr <> nothing) Then
  WScript.Echo " Description:", strDescr  
 end if

 if (strPInfo <> nothing) Then
  WScript.Echo " Parameter Info:", strPInfo  
 end if

 if (strCode <> nothing) Then
  WScript.Echo " Status:", strCode  
 end if

 WScript.Echo ""
 Err.Clear
 set t_Object2 = CreateObject("WbemScripting.SWbemLastError")
 if Err = 0 Then
    WScript.Echo "Got the error object again - this shouldn't have happened!" 
 Else
    Err.Clear
    WScript.Echo "Couldn't get last error again - as expected"
 End if
End If



The following Perl sample demonstrates how to inspect error and error object information.


use strict;
use Win32::OLE;

my ( $t_Service, $t_Object, $t_Object2, $strDescr, $strPInfo, $strCode );

# Close STDERR file handle to eliminate redundant error message
close(STDERR);

# Ask for non-existent class to force error 
$t_Service = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default"); 
$t_Object = $t_Service->Get("Nosuchclass000");

if (defined $t_Object)
{
 print "Got a class\n"; 
}
else
{
 print "\nErr Information:\n\n";
 print Win32::OLE->LastError, "\n";

 # Create the last error object
 $t_Object = new Win32::OLE 'WbemScripting.SWbemLastError';
 print "\nWMI Last Error Information:\n\n";
 print " Operation: ", $t_Object->{Operation}, "\n";
 print " Provider: ", $t_Object->{ProviderName}, "\n";
 
 $strDescr = $t_Object->{Description};
 $strPInfo = $t_Object->{ParameterInfo};
 $strCode = $t_Object->{StatusCode};

 if (defined $strDescr)
 {
  print " Description: ", $strDescr, "\n";  
 }

 if (defined $strPInfo)
 {
  print " Parameter Info: ", $strPInfo, "\n";  
 }

 if (defined $strCode)
 {
  print " Status: ", $strCode, "\n";  
 }

 print "\n";

 $t_Object2 = new Win32::OLE 'WbemScripting.SWbemLastError';
 if (defined $t_Object2)
 {
  print "Got the error object again - this shouldn't have happened!\n";
 }
 else
 {
  print "Couldn't get last error again - as expected\n";
 }
}

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Type library

Wbemdisp.tlb

DLL

Wbemdisp.dll

See also

Scripting API Objects

 

 

Show:
© 2014 Microsoft