IADs::GetInfo 方法 (iads.h)

IADs::GetInfo 方法从基础目录存储加载到此 ADSI 对象的受支持属性的属性缓存值中。

语法

HRESULT GetInfo();

返回值

此方法支持标准返回值以及以下值。

有关详细信息,请参阅 ADSI 错误代码

注解

调用 IADs::GetInfo 函数来初始化或刷新属性缓存。 这类似于从基础目录存储中获取受支持属性的那些属性值。

未初始化的属性缓存不一定为空。 调用 IADs::P utIADs::P utEx 将值放入任何受支持的属性的属性缓存中,并且缓存保持未初始化。

IADs::GetInfo 的显式调用将加载或重新加载整个属性缓存,覆盖所有缓存的属性值。 但隐式调用仅加载缓存中未设置的属性。 始终显式调用 IADs::GetInfo 以检索 ADSI 对象的最新属性值。

由于对 IADs::GetInfo 的显式调用会覆盖属性缓存中的所有值,因此,如果未在 IADs::GetInfo 之前调用 IADs::SetInfo,则对缓存所做的任何更改都将丢失。

对于 ADSI 容器对象, IADs::GetInfo 仅缓存容器的属性值,而不缓存子对象的属性值。

请务必强调 IADs::GetIADs::GetInfo 方法之间的差异。 前者从属性缓存返回给定属性的值,而后者从基础目录存储将所有支持的属性值加载到属性缓存中。

以下代码示例演示 了 IAD::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::GetInfoEx 此函数覆盖指定属性之前缓存的任何值。

示例

下面的代码示例使用由 WinNT 提供程序提供的计算机对象。 支持的属性包括 Owner (“Owner”) , OperatingSystem (“Windows NT”) , OperatingSystemVersion (“4.0”) , Division (“Fabrikam”) , ProcessorCount (“Uniprococesor Free”) , Processor (“x86 系列 6 型号 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

下面的代码示例是一个客户端脚本,演示 IAD::GetInfo 方法的效果。 支持的属性包括 Owner (“Owner”) , OperatingSystem (“Windows NT”) , OperatingSystemVersion (“4.0”) , Division (“Fabrikam”) , ProcessorCount (“Uniprococesor Free”) , Processor (“x86 系列 6 型号 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

另请参阅

IAD

IADs::Get

IADs::GetEx

IADs::GetInfoEx

属性缓存