Session.Create method
Creates a new instance of a resource and returns the endpoint reference (EPR) of the new object.
Syntax
Session.Create( _
ByVal resourceUri, _
ByVal resource, _
[ ByVal flags ] _
)
Parameters
-
resourceUri [in]
-
Identifier of the resource to create.
This parameter can contain one of the following:
- URI with one or more selectors. Be aware that the WMI plug-in does not support creating any resource other than a WS-Management Protocol listener.
- ResourceLocator object which may contain selectors, fragments, or options.
- WS-Addressing endpoint reference as described in the WS-Management protocol standard. For more information about the public specification for WS-Management protocol, see Management Specifications Index Page.
-
resource
-
The XML that contains resource content.
-
flags [in, optional]
-
Reserved. Must be set to 0.
Return value
The EPR of the new resource.
Remarks
Session.Create is only used for creating new instances of a resource. Use the Session.Put method to update existing instances of a resource. After you obtain the new resource URI, you can call Session.Get to retrieve the new object. The new object contains any properties that the resource provider assigns when creating the new object. For example, if you create a new WS-Management protocol listener and retrieve the listener object using Session.Get, then you also obtain the Port, Enabled, and ListeningOn properties.
Be aware that the WMI plug-in does not support creating any resource other than a WS-Management protocol listener.
The following syntax is used to call this method.
uri = session.Create("<resourceUri>", "<resource>")
Examples
The following VBScript code example calls Session.Create to create a listener on the local computer.
'Create a WSMan object
Set oWsman = CreateObject( "WSMAN.Automation" )
'Create a Session object
Set oSession = oWsman.CreateSession
'Define resourceUri and inputXml
resourceUri = "http://schemas.microsoft.com/wbem/wsman/1/"_
& "config/Listener?Address=*+Transport=HTTP"
inputXml = _
"<cfg:Listener xmlns:cfg=""https://schemas.dmtf.org/wbem/wsman/1/"_
& "config/Listener.xsd"">" _
& "<cfg:Hostname>" & GetFQDNName() & "</cfg:Hostname>" _
& "</cfg:Listener>"
'Perform the create operation.
response = oSession.Create( resourceUri, inputXml )
WScript.Echo "Response message: " & Chr(10) & response
Function GetFQDNName()
Dim oShell, userDNSDomain, localComputerName
Set oShell = CreateObject("WScript.Shell")
userDNSDomain = oShell.ExpandEnvironmentStrings("%USERDNSDOMAIN%")
localComputerName = _
oShell.ExpandEnvironmentStrings("%ComputerName%")
If userDNSDomain = "%USERDNSDOMAIN%" Then
GetFQDNName= localComputerName
Else
GetFQDNName= localComputerName & "." & userDNSDomain
End If
End Function
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows Vista |
Minimum supported server |
Windows Server 2008 |
Header |
|
IDL |
|
Library |
|
DLL |
|