共用方式為


從舊屬性建立新的實例

聯結檢視類別包含來源類別實例的屬性,這些屬性是由通用屬性值所連接,例如Class1.Prop1 = Class2.Prop2。 聯結檢視類別中的每個實例都包含不同類別實例的一部分。

您可以將聯結檢視類別根據屬性值的不等,例如Class1.Prop1<>Class2.Prop2,其中Prop1 和 Prop2不會對應至檢視類別中的相同屬性。

當您尋找的資訊包含在個別但相關的類別中時,聯結檢視類別會很有説明。 例如,如果您想要印表機的相關資訊和印表機組態的相關資訊,您可以建立聯結檢視類別,其中包含 Win32_Printer 類別的一些屬性,以及 Win32_PrinterConfiguration 類別的某些屬性。 如果沒有檢視提供者,您必須擷取併合並個別實例的屬性,以取得您需要的資訊。

下列程式描述如何建立聯結檢視類別。

建立聯結檢視類別

  1. 使用 JoinOn 字串限定詞開始類別定義。

    JoinOnAssociationUnion限定詞互斥。

  2. 如有必要,請套用 PostJoinFilter 限定詞,以篩選聯結類別中您想要的實例。

    PostJoinFilter提供者可讓您將檢視類別的實例限制為符合特定條件的實例。

  3. 使用 ViewSources 限定詞建立定義檢視類別來源實例的查詢。

  4. 使用 ViewSpaces 限定詞定義來源實例所在命名空間的名稱和位置。

  5. 使用 PropertySources 限定詞,在聯結檢視類別中定義您想要的屬性。

    當屬性根據相等加入聯結檢視時,兩個來源屬性必須對應在一個 PropertySources 限定詞中。

    下列程式碼範例顯示一個 PropertySources 限定詞中對應的兩個屬性。

    [PropertySources{"IDProcess", "IDProcess"}] Uint32 ProcessID;
    

    藉由使用 HiddenDefault 限定詞,您可以標記屬於來源類別的屬性。

下列程式碼範例示範從效能監視器提供者類別建立的聯結檢視類別,Win32_PerfRawData_PerfProc_ProcessWin32_PerfRawData_PerfProc_ThreadProcessID屬性聯結的兩個類別屬性。

#pragma namespace("\\\\.\\root\\cimv2")

instance of __Win32Provider as $DataProv
{
    Name = "MS_VIEW_INSTANCE_PROVIDER";
    ClsId = "{AA70DDF4-E11C-11D1-ABB0-00C04FD9159E}";
    ImpersonationLevel = 1;
    PerUserInitialization = "True";
    
};

instance of __InstanceProviderRegistration
{
    Provider = $DataProv;
    SupportsPut = True;
    SupportsGet = True;
    SupportsDelete = True;
    SupportsEnumeration = True;
    QuerySupportLevels = {"WQL:UnarySelect"};
};

[JoinOn("Win32_PerfRawData_PerfProc_Process.IDProcess = 
    Win32_PerfRawData_PerfProc_Thread.IDProcess"), 
ViewSources{"SELECT Name, IDProcess, PriorityBase 
    FROM Win32_PerfRawData_PerfProc_Process", 
    "SELECT Name, IDProcess, ThreadState, 
    PriorityCurrent FROM Win32_PerfRawData_PerfProc_Thread"},
ViewSpaces{"\\\\.\\root\\cimv2", "\\\\.\\root\\cimv2"},
dynamic: ToInstance, provider("MS_VIEW_INSTANCE_PROVIDER")]

class JoinedProcessThread
{
    [PropertySources{"IDProcess", "IDProcess"}] 
        Uint32 ProcessID;
    [PropertySources{"Name", ""}] 
        String PName;
    [PropertySources{"", "Name"}, key]   
        String TName;
    [PropertySources{"", "ThreadState"}] 
        Uint32 State;
    [PropertySources{"PriorityBase", ""}] 
        Uint32 BasePriority;
    [PropertySources{"", "PriorityCurrent"}] 
        Uint32 CurrentPriority;    
};