Session.Create 方法

建立資源的新實例,並傳回 新物件 (EPR) 端點參考

語法

Session.Create( _
  ByVal resourceUri, _
  ByVal resource, _
  [ ByVal flags ] _
)

參數

resourceUri [in]

要建立之資源的識別碼。

此參數可以包含下列其中一項:

資源

包含資源內容的 XML。

旗標 [in, 選擇性]

保留的。 必須設定為 0。

傳回值

新資源的 EPR。

備註

Session.Create 僅用於建立資源的新實例。 使用 Session.Put 方法來更新資源的現有實例。 取得新的資源 URI 之後,您可以呼叫 Session.Get 來擷取新的物件。 新物件包含資源提供者在建立新物件時指派的任何屬性。 例如,如果您建立新的WS-Management通訊協定 接聽程式 ,並使用 Session.Get擷取接聽程式物件,則也會取得 PortEnabledListeningOn 屬性。

請注意, WMI 外掛程式 不支援建立WS-Management通訊協定接聽程式以外的任何資源。

下列語法是用來呼叫這個方法。

uri = session.Create("<resourceUri>", "<resource>")

範例

下列 VBScript 程式碼範例會呼叫 Session.Create ,以在本機電腦上建立接聽程式。

'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

規格需求

需求
最低支援的用戶端
Windows Vista
最低支援的伺服器
Windows Server 2008
標頭
WSManDisp.h
IDL
WSManDisp.idl
程式庫
WSManDisp.tlb
DLL
WSMAuto.dll

另請參閱

工作階段

WS-Management 通訊協定