共用方式為


IADs::GetInfo 方法 (iads.h)

IADs::GetInfo方法會從基礎目錄存放區載入這個 ADSI 物件所支援屬性的屬性快取值。

Syntax

HRESULT GetInfo();

傳回值

這個方法支援標準傳回值,以及下列專案。

如需詳細資訊,請參閱 ADSI 錯誤碼

備註

系統會呼叫 IADs::GetInfo 函式來初始化或重新整理屬性快取。 這類似于從基礎目錄存放區取得所支援屬性的屬性值。

未初始化的屬性快取不一定是空的。 呼叫 IADs::P utIADs::P utEx ,將值放入任何支援屬性的屬性快取中,而且快取維持未初始化狀態。

明確呼叫 IADs::GetInfo會載入或重載整個屬性快取,並覆寫所有快取的屬性值。 但隱含呼叫只會載入快取中未設定的屬性。 請一律明確呼叫 IADs::GetInfo ,以擷取 ADSI 物件的最新屬性值。

由於明確呼叫 IADs::GetInfo會覆寫屬性快取中的所有值,因此如果IADs::SetInfo 在 IADs::GetInfo 之前未叫用 IADs::GetInfo,則對快取所做的任何變更都會遺失。

針對 ADSI 容器物件, IADs::GetInfo 只會快取容器的屬性值,但不會快取子物件的屬性值。

請務必強調 IADs::GetIADs::GetInfo 方法之間的差異。 前者會從屬性快取傳回指定屬性的值,而後者則會從基礎目錄存放區將所有支援的屬性值載入屬性快取中。

下列程式碼範例說明 IADs::GetIADs::GetInfo 方法之間的差異。

Set x = GetObject("LDAP://CN=Administrator,CN=Users,DC=Fabrikam,DC=com")
                                     ' The first IADs::Get calls
                                     ' GetInfo implicitly.
Debug.Print x.Get("homePhone")       ' Assume value is '999-9999'. 
x.Put "homePhone", "868-4449"        ' Put with no commit(SetInfo)
Debug.Print x.Get("homePhone")       ' Value='868-4449' from the cache.
x.GetInfo                            ' Refresh the cache, get the data 
                                     ' from the directory.
Debug.Print x.Get("homePhone")       ' Value will be '999-9999'.

為了提升效能,請明確呼叫 IADs::GetInfoEx 以重新整理特定屬性。 此外,如果必須存取物件的操作屬性值,則必須呼叫IADs::GetInfoEx,而不是 IADs::GetInfo。 此函式會覆寫任何先前快取的指定屬性值。

範例

下列程式碼範例會使用 WinNT 提供者所提供的電腦物件。 支援的屬性包括 擁有者 (「擁有者」) , OperatingSystem (「Windows NT」) , OperatingSystemVersion (「4.0」) , Division (「Fabrikam」) , ProcessorCount (「Uniprococessor Free」) , Processor (「x86 系列 6 Model 5 逐步執行 1」) 。 預設值會顯示在括弧中。

Dim pList As IADsPropertyList
Dim pEntry As IADsPropertyEntry
Dim pValue As IADsPropertyValue

On Error GoTo Cleanup
 
Set pList = GetObject("WinNT://localhost,computer")
 
' pList now represents an uninitialized empty property cache.
pList.Put "Owner", "JeffSmith"  ' Property cache remains uninitialized,
                               ' but with one property value.
count = pList.PropertyCount  ' count = 1.
MsgBox "Number of property found in the property cache: " & count
 
v = pList.Get("Division")   ' pList.GetInfo is called implicitly
ShowPropertyCache           ' This will display "JeffSmith" for Owner,
                            ' "Fabrikam" for Division, "Windows NT" for
                            ' OperatingSystem, and so on.
 
pList.GetInfo                ' Refreshes the entire cache, overwriting 
                             ' "JeffSmith" for the Owner property.
ShowPropertyCache            ' This will display "Owner" for Owner,
                             ' "Fabrikam" for Division, "Windows NT" for
                             ' OperatingSystem, and so on.

Cleanup:
    If (Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set pList = Nothing
    Set pEntry = Nothing
    Set pValue = Nothing

 
Private Sub ShowPropertyCache()
    For I = 0 To pList.PropertyCount-1
       Set pEntry = pList.Item(I)
       Debug.Print pEntry.Name
       For Each v In pEntry.Values
           Set pValue = v
           Debug.Print "   " & pvalue.CaseIgnoreString
       Next
    Next
End Sub

下列程式碼範例是用戶端腳本,說明 IADs::GetInfo 方法的效果。 支援的屬性包括 擁有者 (「擁有者」) , OperatingSystem (「Windows NT」) , OperatingSystemVersion (「4.0」) , Division (「Fabrikam」) , ProcessorCount (「Uniprococessor Free」) , Processor (「x86 系列 6 Model 5 逐步執行 1」) 。 預設值會顯示在括弧中。

<html>
<body>
 <table>
    <tr>
       <td>Owner:</td>
       <td><input type=text name=txtOwner></td>
    </tr>
    <tr>
       <td>Operating System:</td>
       <td><input type=text name=txtOS></td>
    </tr>
    <tr>
       <td>Operating System Version:</td>
       <td><input type=text name=txtOSV></td>
    </tr>
    <tr>
       <td>Division:</td>
       <td><input type=text name=txtDiv></td>
    </tr>
 </table>

 <input type=button onClick = "showGetInfo()">
</body>

<script language="vbscript">
Dim pList 

sub showGetInfo()
  Set oFac = CreateObject("ADsFactory")
  path = "WinNT://Fabrikam"
  ADS_SECURE_AUTH = 1
  On Error Resume Next

' Browser security requires enabled/Prompt for "Initialize and 
' script ActiveX Controls not marked as safe"
  Set pList=oFac.OpenDSObject(path,vbNullString,vbNullString,ADS_SECURE_AUTH)
   
  ' pList now represents an uninitialized empty property cache
  pList.Put "Owner" "JeffSmith"  ' Property cache remain uninitialized
                                 ' but with one property value.
   
  v = pList.Get("Division")   ' pList.GetInfo is called implicitly
  ShowPropertyCache           ' This will display "JeffSmith" for Owner,
                              ' "Fabrikam" for Division, "Windows NT"
                              ' for OperatingSystem, and so on.
 
  pList.GetInfo                ' Refreshes entire cache, overwriting 
                               ' "JeffSmith" for the Owner property.
  ShowPropertyCache            ' This will display "Owner" for Owner,
                               ' "Fabrikam" for Division, "Windows NT"
                               ' for OperatingSystem, and so on.
end sub

sub ShowPropertyCache()
  txtOwner.value = pList.Get("Owner")
  txtDiv.value = pList.Get("Division")
  txtOS.Value = pList.Get("OperatingSystem")
  txtOSV.value = pList.Get("OperatingSystemVersion")
end sub
</script>

</html>

下列程式碼範例會醒目提示 Get 和 GetInfo 的效果。 為了簡潔起見,會省略錯誤檢查。

IADs *pADs;
IADsPropertyList *pList;
BSTR bstr;
VARIANT var;
HRESULT hr;
 
hr = ADsGetObject(L"WinNT://somecomputer,computer",
                  IID_IADsPropertyList,
                  (void**)&pList);

if(!(hr==S_OK)){return hr;}

VariantInit(&var);
 
// Get the number of property entries, should be zero.
long pCount;      
hr = pList->get_PropertyCount(&pCount);
printf("    prop count = %d\n",pCount);     // 0 for empty cache.
 
hr = pList->QueryInterface(IID_IADs, (void**)&pADs);
 
 
// Set "Owner=JeffSmith" in the property cache.
V_BSTR(&var) = SysAllocString(L"JeffSmith");
V_VT(&var) = VT_BSTR;
hr = pADs->Put(CComBSTR("Owner"), var);
VariantClear(&var);
 
// This time the number of property entries should read one (1).
hr = pList->get_PropertyCount(&pCount);
printf("    prop count = %d\n",pCount);    // 1 for what was set.
 
// The following Get invokes GetInfo implicitly, but 
// the cache (that is, "Owner=JeffSmith") remains intact.
hr = pADs->Get(CComBSTR("Division"), &var);  
printf("    division   = %S\n", V_BSTR(&var));
VariantClear(&var);
 
hr = pADs->Get(CComBSTR("Owner"), &var);
printf("    owner      = %S\n", V_BSTR(&var));  // Owner = JeffSmith
VariantClear(&var);
 
// The following GetInfo call refreshes the entire prop cache.
// Now Owner is no longer "JeffSmith", but the value stored in the
// persistent store, for example, "BenSmith".
hr = pADs->GetInfo();
 
hr = pADs->Get(CComBSTR("Owner"), &var);
printf("    owner      = %S\n", V_BSTR(&var));  // Owner = BenSmith
VariantClear(&var);
 
// ...

if(pADs)
   pADs->Release();

if(pList)
   pList->Release();

需求

   
最低支援的用戶端 Windows Vista
最低支援的伺服器 Windows Server 2008
目標平台 Windows
標頭 iads.h
Dll Activeds.dll

另請參閱

IADs

IADs::Get

IADs::GetEx

IADs::GetInfoEx

屬性快取