共用方式為


設定 Visual C++ 6.0 以進行 ADSI 開發

Microsoft Visual C++ 6.0 開發系統可用來開發企業應用程式。 若要設定 Visual C++ 6.0 環境以開發 ADSI 應用程式,請執行下列步驟:

設定 Microsoft Visual C++ 6.0 開發環境

  1. 指向 include 和 library 目錄。 選取 工具 |選項。 按兩下 [ 目錄] 索引標籤,並指定ADSI頭檔的路徑。
  2. 在您的專案中包含 Activeds.h 檔案。
  3. 將 Activeds.lib 和 Adsiid.lib 檔案新增至專案的連結器輸入。
  4. 開始使用ADSI進行程序設計。

登入 Windows 網域。 您也必須具有修改 Active Directory 中數據的許可權。 根據預設,管理員 istrator 具有此許可權。 若要輸入此程式碼範例:

範例 Visual C++ 應用程式:在網域中建立使用者

  1. 啟動 Visual C++ 6.0。

  2. 建立獨立可執行文件專案。 它可以是 MFC、ATL 或控制台應用程式。

  3. 請遵循先前的步驟來設定您的專案。

  4. 輸入下列程式代碼範例。 將 “LDAP://CN=users,DC=fabrikam,DC=com” 字符串取代為您網域中容器的 ADsPath。 您也應該將使用者名稱 「jeffsmith」 取代為您網域中唯一的用戶名稱。

    #include "stdafx.h"
    #include "activeds.h"
    
    int main(int argc, char* argv[])
    {
        HRESULT hr;
        IADsContainer *pCont;
        IDispatch *pDisp=NULL;
        IADs *pUser;
    
         // Initialize COM before calling any ADSI functions or interfaces.
         CoInitialize(NULL);
    
        hr = ADsGetObject( L"LDAP://CN=users,DC=fabrikam,DC=com", 
                                   IID_IADsContainer, 
                                   (void**) &pCont );
    
        if ( !SUCCEEDED(hr) )
        {
            return 0;
        }
    
        //-----------------
        // Create a user
        //-----------------
    
        hr = pCont->Create(CComBSTR("user"), CComBSTR("cn=jeffsmith"), &pDisp );
    
        // Release the container object.    
        pCont->Release();
    
        if ( !SUCCEEDED(hr) )
        {
            return 0;
        }
    
        hr = pDisp->QueryInterface( IID_IADs, (void**) &pUser );
    
        // Release the dispatch interface.
        pDisp->Release();
    
        if ( !SUCCEEDED(hr) )
        {    
            return 0;
        }
    
        // Commit the object data to the directory.
        pUser->SetInfo();
    
        // Release the object.
        pUser->Release();
    
        CoUninitialize();
    }
    
  5. 建置並執行應用程式。 若要確認使用者已建立,請使用 Active Directory 使用者和電腦 管理工具。