SWbemObjectPath object
Use the methods and properties of the SWbemObjectPath object to construct and validate an object path. This object can be created by the VBScript CreateObject call.
Members
The SWbemObjectPath object has these types of members:
Methods
The SWbemObjectPath object has these methods.
Method | Description |
---|---|
SetAsClass | Forces the path to address a WMI class. |
SetAsSingleton | Forces the path to address a singleton WMI instance. |
Properties
The SWbemObjectPath object has these properties.
Property | Access type | Description |
---|---|---|
Authority |
Read/write |
String that defines the Authority component of the object path. |
Class |
Read/write |
Name of the class that is part of the object path. |
DisplayName |
Read/write |
String that contains the path in a form that can be used as a moniker display name. See Creating a WMI Application or Script. |
IsClass |
Read-only |
Boolean value that indicates if this path represents a class. This is analogous to the __Genus property in the COM API. |
IsSingleton |
Read-only |
Boolean value that indicates if this path represents a singleton instance. |
Keys |
Read-only |
An SWbemNamedValueSet object that contains the key value bindings. |
Locale |
Read/write |
String that contains the locale for this object path. |
Namespace |
Read/write |
Name of the namespace that is part of the object path. This is the same as the __Namespace property in the COM API. |
ParentNamespace |
Read-only |
Name of the parent of the namespace that is part of the object path. |
Path |
Read/write |
Contains the absolute path. This is the same as the __Path system property in the COM API. This is the default property of this object. |
Relpath |
Read/write |
Contains the relative path. This is the same as the __Relpath system property in the COM API. |
Security_ |
Read-only |
Used to read or change the security settings. |
Server |
Read/write |
Name of the server. This is the same as the __Server system property in the COM API. |
Examples
The following VBScript code sample demonstrates how to build object paths.
on error resume next
Set ObjectPath = CreateObject("WbemScripting.SWbemObjectPath")
ObjectPath.Server = "dingle"
ObjectPath.Namespace = "root/default/something"
ObjectPath.Class = "ho"
ObjectPath.Keys.Add "fred1", 10
ObjectPath.Keys.Add "fred2", -34
ObjectPath.Keys.Add "fred3", 65234654
ObjectPath.Keys.Add "fred4", "Wahaay"
ObjectPath.Keys.Add "fred5", -786186777
if err <> 0 then
WScript.Echo err.number
end if
WScript.Echo "Pass 1:"
WScript.Echo ObjectPath.Path
WScript.Echo ObjectPath.DisplayName
WScript.Echo ""
ObjectPath.Security_.ImpersonationLevel = 3
WScript.Echo "Pass 2:"
WScript.Echo ObjectPath.Path
WScript.Echo ObjectPath.DisplayName
WScript.Echo ""
ObjectPath.Security_.AuthenticationLevel = 5
WScript.Echo "Pass 3:"
WScript.Echo ObjectPath.Path
WScript.Echo ObjectPath.DisplayName
WScript.Echo ""
Set Privileges = ObjectPath.Security_.Privileges
if err <> 0 then
WScript.Echo Hex(Err.Number), Err.Description
end if
Privileges.Add 8
Privileges.Add 20, false
WScript.Echo "Pass 4:"
WScript.Echo ObjectPath.Path
WScript.Echo ObjectPath.DisplayName
WScript.Echo ""
ObjectPath.DisplayName = "winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktprivacy,(Debug,!IncreaseQuota, CreatePagefile ) }!//fred/root/blah"
WScript.Echo "Pass 5:"
WScript.Echo ObjectPath.Path
WScript.Echo ObjectPath.DisplayName
WScript.Echo ""
The following Perl code sample demonstrates how to build object paths.
use strict;
use Win32::OLE;
use constant FALSE=>"false";
my ( $ObjectPath, $Privileges );
eval { $ObjectPath = new Win32::OLE 'WbemScripting.SWbemObjectPath'; };
unless($@)
{
eval
{
$ObjectPath->{Server} = "dingle";
$ObjectPath->{Namespace} = "root/default/something";
$ObjectPath->{Class} = "ho";
$ObjectPath->{Keys}->Add("fred1", 10);
$ObjectPath->{Keys}->Add("fred2", -34);
$ObjectPath->{Keys}->Add("fred3", 65234654);
$ObjectPath->{Keys}->Add("fred4", "Wahaay");
$ObjectPath->{Keys}->Add("fred5", -786186777);
};
unless($@)
{
print "\n";
print "Pass 1:\n";
print $ObjectPath->{Path}, "\n";
print $ObjectPath->{DisplayName} , "\n\n";
$ObjectPath->{Security_}->{ImpersonationLevel} = 3 ;
print "Pass 2:\n";
print $ObjectPath->{Path}, "\n";
print $ObjectPath->{DisplayName} , "\n\n";
$ObjectPath->{Security_}->{AuthenticationLevel} = 5 ;
print "Pass 3:\n";
print $ObjectPath->{Path}, "\n";
print $ObjectPath->{DisplayName} , "\n\n";
eval { $Privileges = $ObjectPath->{Security_}->{Privileges}; };
unless($@)
{
$Privileges->Add(8);
$Privileges->Add(20,FALSE);
print "Pass 4:\n";
print $ObjectPath->{Path}, "\n";
print $ObjectPath->{DisplayName} , "\n\n";
$ObjectPath->{DisplayName} = "winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktprivacy,(Debug,!IncreaseQuota, CreatePagefile ) }!//fred/root/blah";
print "Pass 5:\n";
print $ObjectPath->{Path}, "\n";
print $ObjectPath->{DisplayName} , "\n";
}
else
{
print STDERR Win32::OLE->LastError, "\n";
}
}
else
{
print STDERR Win32::OLE->LastError, "\n";
}
}
else
{
print STDERR Win32::OLE->LastError, "\n";
}
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows Vista |
Minimum supported server |
Windows Server 2008 |
Header |
|
Type library |
|
DLL |
|
CLSID |
CLSID_SWbemObjectPath |
IID |
IID_ISWbemObjectPath |