Setting Up Visual C++ 6.0 for ADSI Development

from MSDN

 

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 2000 or Windows Server 2003 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.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值