Bagikan melalui


Metode Session.Get

Mengambil sumber daya yang ditentukan oleh URI dan mengembalikan representasi XML dari instans sumber daya saat ini.

Sintaks

Session.Get( _
  ByVal resourceUri, _
  [ ByVal flags ] _
)

Parameter

resourceUri [in]

Pengidentifikasi sumber daya yang akan diambil.

Parameter ini dapat berisi salah satu hal berikut:

  • URI dengan atau tanpa pemilih. Saat memanggil metode Get dengan pemilih untuk mendapatkan sumber daya WMI, gunakan properti kunci atau properti objek. Misalnya, dalam contoh kode Visual Basic Scripting Edition (VBScript) berikut, kunci ditentukan oleh Win32_Service?Name=winmgmt. Untuk kelas singleton, seperti Win32_LocalTime, Anda tidak dapat menggunakan pemilih.

    strResourceUri = "http://schemas.microsoft.com/" _ 
        & "wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt"
    
    strResourceUri = "http://schemas.microsoft.com/" _ 
        & "wbem/wsman/1/wmi/root/cimv2/Win32_LocalTime"
    
  • Objek ResourceLocator yang mungkin berisi pemilih, fragmen, atau opsi.

  • Referensi titik akhir WS-Addressing seperti yang dijelaskan dalam standar protokol WS-Management. Untuk informasi selengkapnya tentang spesifikasi publik untuk Protokol Manajemen WS, lihat Halaman Indeks Spesifikasi Manajemen.

bendera [in, opsional]

Dicadangkan. Harus diatur ke 0.

Menampilkan nilai

Representasi XML dari sumber daya.

Contoh

Contoh kode VBScript berikut mengambil representasi XML dari instans Win32_Service yang mewakili layanan WMI Winmgmt di komputer lokal.


'Create a WSMan object.
Set objWsman = CreateObject( "WSMAN.Automation" )
If objWsman is Nothing Then
    WScript.Echo "Failed to create WSMAN Automation object"
    WScript.Quit
End If 

'Create a Session object.
Set objSession = objWsman.CreateSession
If objSession is Nothing Then
    WScript.Echo "Failed to create WSMAN Session object"
    WScript.Quit
End If 


strResourceUri = "http://schemas.microsoft.com/" _ 
    & "wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt"

On Error Resume Next
xmlResource = objSession.Get( strResourceUri )
WScript.Echo "Response message: " & Chr(10) & xmlResource
If Err.Number <> 0 Then
    DisplayErrorInfo
End If
On Error Goto 0

Sub DisplayErrorInfo()
    WScript.Echo "An error has occurred."     
    WScript.Echo
    WScript.Echo "Error Info"
    WScript.Echo "-----------"
    WScript.Echo "Number      : 0x" & hex(Err.number)
    WScript.Echo "Description : " & Err.Description
    WScript.Echo "Source      : " & Err.Source
    WScript.Echo "HelpFile    : " & Err.helpfile
    WScript.Echo "HelpContext : " & Err.HelpContext    
    WScript.Echo Err.Clear    
End Sub

Contoh kode VBScript berikut mengambil instans layanan WMI Winmgmt dari komputer jarak jauh. Komputer jarak jauh diidentifikasi dengan nama domain yang sepenuhnya memenuhi syarat (servername.domain.com). Satu-satunya perbedaan antara versi lokal dan jarak jauh adalah spesifikasi komputer jarak jauh dalam panggilan ke WSMan.CreateSession.

Const RemoteComputer = "servername.domain.com"

'Create a WSMan object.
Set objWsman = CreateObject( "WSMAN.Automation" )
If objWsman is Nothing Then
    WScript.Echo "Failed to create WSMAN Automation object"
    WScript.Quit
End If 

'Create a Session object.
Dim objSession
Set objSession = objWsman.CreateSession( "https://" & RemoteComputer )
If objSession is Nothing Then
    WScript.Echo "Failed to create WSMAN Session object"
    WScript.Quit
End If 


strResourceUri = "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/" _ 
    & "Win32_Service?Name=winmgmt"


On Error Resume Next
xmlResource = objSession.Get( strResourceUri )
WScript.Echo "Response message: " & Chr(10) & xmlResource
If Err.Number <> 0 Then
    DisplayErrorInfo
End If
On Error Goto 0

Sub DisplayErrorInfo()
    WScript.Echo "An error has occurred."     
    WScript.Echo
    WScript.Echo "Error Info"
    WScript.Echo "-----------"
    WScript.Echo "Number      : 0x" & hex(Err.number)
    WScript.Echo "Description : " & Err.Description
    WScript.Echo "Source      : " & Err.Source
    WScript.Echo "HelpFile    : " & Err.helpfile
    WScript.Echo "HelpContext : " & Err.HelpContext    
    WScript.Echo Err.Clear    
End Sub

Persyaratan

Persyaratan Nilai
Klien minimum yang didukung
Windows Vista
Server minimum yang didukung
Windows Server 2008
Header
WSManDisp.h
IDL
WSManDisp.idl
Pustaka
WSManDisp.tlb
DLL
WSMAuto.dll

Lihat juga

Sesi