大网数据广告活动
域与目录服务

Setting Up Visual C++ 6.0 for ADSI Development

· 52CE 我爱测

This topic shows you how to set up C++ in Visual Studio so you can develop an ADSI application.

The Microsoft Visual C++ 6.0 development system can be used to develop enterprise applications. To set up your Visual C++ 6.0 environment to develop an ADSI application, perform the following steps:

Setting Up the Microsoft Visual C++ 6.0 Development Environment

  1. Point to the include and library directory. Select Tools | Options. Click the Directory tab, and specify the path to the ADSI header files.
  2. Include the Activeds.h file in your project.
  3. Add the Activeds.lib and Adsiid.lib files to the linker input for your project.
  4. Begin programming with ADSI.

Log on to a Windows domain. You must also have permission to modify data in Active Directory. By default, the Administrator has this privilege. To enter this code example:

A Sample Visual C++ Application: Creating a User in a Domain

  1. Start Visual C++ 6.0.

  2. Create a standalone executable project. It can be either an MFC, ATL, or Console Application.

  3. Follow the previous steps to set up your project.

  4. Enter the following code example. Replace the "LDAP://CN=users,DC=fabrikam,DC=com" string with the ADsPath of a container in your domain. You should also replace the user name "jeffsmith" with a user name that is unique in your domain.

    #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. Build and run the application. To verify that the user has been created, use the Active Directory Users and Computers management tool.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。