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

Programming ADSI with Java/COM

· 52CE 我爱测

Using the Microsoft virtual machine for Java (Microsoft VM) and Microsoft Java Compiler, you have access to all the ADSI features exposed through any ADSI COM components, from a Java/COM application.

Using the Microsoft virtual machine for Java (Microsoft VM) and Microsoft Java Compiler, you have access to all the ADSI features exposed through any ADSI COM components, from a Java/COM application. The following Java code example shows the elements necessary to bind to an ADSI object and invoke methods on that object. The required ADSI API functions and object methods are exposed through Activeds.dll.

import activeds.*;       // ADSI COM Wrapper classes
import com.ms.com.*;     // to use _Guid data type in COM.

public Class SimpleADSI 
{
    IADs obj;
    String path = "WinNT://domain/machine,computer";
    _Guid riid = IADs.iid;
    public static void main(String args[]) 
    {
        try 
        {
            obj = (IADs)ADsGetObject(path, riid);
            System.out.println( "Object name:  " + obj.getName() );
            System.out.println( "      class:  " + obj.getSchema() );
            System.out.println( "    ADsPath:  " + obj.getADsPath() );
            System.out.println( "     parent:  " + obj.getParent() );
        }
        catch (Exception e) 
        {
            System.out.println( "SimpleADSI Error: " + e.toString() );
        }
    }

    /** @dll.import("activeds", ole) */
    private static native IUnknown ADsGetObject(String path, _Guid riid);
}

The argument in the first import statement refers to Java Wrapper classes packaged in Activeds.dll. Use Visual J++ to create the wrapper classes and include them in your project, following the procedure below.

To create wrapper classes and include them in your project

  1. In a Visual J++ project, select Add Com Wrapper... from the Project menu.
  2. Select "Active DS Type Library" from the Installed Components: from the COM Wrappers dialog. If the type library is not shown in the list box, click the Browse... button, navigate to the directory where Activeds.tlb is stored, and then select the type library.

Visual J++ creates the activeds package for the Java Wrapper classes and include the package into the project's default path. For more information, see the activeds package in the Project Explore pane on the Visual J++ window.

To get an ADSI object that cannot be cocreated, use one of the exposed ADSI API functions, for example, ADsGetObject or ADsOpenObject, which are also packaged in Activeds.dll. Microsoft J/Direct provides access to these and other native APIs. This is illustrated by the last two lines of the code example, above.

When compiling, ensure that Microsoft Language Extension is enabled. To do this, select <project> Properties... from the Project menu in the Visual J++ project window. Then, click the Compile tab in the <project> Properties dialog. Clear the Disable Microsoft Language Extensions check box. If compiling from the command line, use "/x-" switch, for example:

jvc /x- SimpleADSI.java

Finally, in order for the virtual machine to load the COM component, the dynamic-link library (DLL) must be visible on the system path. If a "java.lang.UnsatisfiedLinkError" error is returned, set the PATH to include the path that contains the required DLL. For example, if Activeds.dll has been installed in c:\adsi\lib, issue the following command from the command line:

set PATH = %PATH%; c:\adsi\lib

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)

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

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