简体   繁体   English

使用 Jacob 从远程系统读取 Windows 注册表信息

[英]Read windows registry info from remote system using Jacob

Im trying to run some WMI queries using JACOB, and so far i've been successfull in getting the services and processes however i need to query the registry to see if a certain key is there我正在尝试使用 JACOB 运行一些 WMI 查询,到目前为止我已经成功获取了服务和进程,但是我需要查询注册表以查看是否存在某个键

i've stummbled across this link我偶然发现了这个链接

but i dont understand how to implement it但我不明白如何实现它

in order to query the services i've used the following code为了查询服务,我使用了以下代码

ActiveXComponent wmi = null;
        wmi = new ActiveXComponent("WbemScripting.SWbemLocator"); <-- side question what is the WbemScripting...
variantParameters[0] = new Variant("localhost");
        variantParameters[1] = new Variant("root\\cimv2"); <-- what is this root?
String query = "Select ExitCode,Name,ProcessId,StartMode,State,Status from Win32_Service where State='Running' and Name='MSDTC'";
        Variant vCollection = wmiconnect
                .invoke("ExecQuery", new Variant(query));

is there a place with decent documentation for this?有没有像样的文档的地方? and how to implement queries on the registry?以及如何实现对注册表的查询?

Thanks谢谢

UPDATE更新

Im trying a new implementation where i try to call the StdRegProv我正在尝试一个新的实现,我尝试调用StdRegProv

and i have the following code我有以下代码

        int HKEY_LOCAL_MACHINE = 0x80000002;
    String strKeyPath = "SYSTEM\\CurrentControlSet\\Services";
    String [] sNames = new String [5];
    ActiveXComponent wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
    // no connection parameters means to connect to the local machine
    Variant variantParameters[] = new Variant[4];
    variantParameters[0] = new Variant("192.168.1.2");
    variantParameters[1] = new Variant("root\\default");
    variantParameters[2] = new Variant("admin");
    variantParameters[3] = new Variant("pass");
    Dispatch services = wmi.invoke("ConnectServer", variantParameters).toDispatch();
    Dispatch oReg = Dispatch.call(services, "Get", "StdRegProv").toDispatch(); 

    Variant ret = Dispatch.call(oReg, "EnumKey", HKEY_LOCAL_MACHINE, strKeyPath, sNames); 
    System.out.println("EnumKey: HKEY_LOCAL_MACHINE\\"+strKeyPath+"="+ret);

I was hoping to get the sNames array filled with data but its just nulls我希望用数据填充 sNames 数组,但它只是空值

I was unable to do it with Jacob but succeeded using j-interop library我无法与 Jacob 一起完成,但成功使用 j-interop 库

here is the code that cost me so much suffering这是让我痛苦不堪的代码

IJIAuthInfo authInfo = new JIDefaultAuthInfoImpl("remoteComputerIpAddress", "wmiUserName", "wmiUserPassword");
        IJIWinReg registry = null;
        try {
            registry = JIWinRegFactory.getSingleTon().getWinreg(authInfo, "remoteComputerIpAddress", true);
            JIPolicyHandle policyHandle = registry.winreg_OpenHKLM();
            JIPolicyHandle policyHandle2 = registry.winreg_OpenKey(policyHandle, "SOFTWARE\\wisemon",
                    IJIWinReg.KEY_ALL_ACCESS);
            // JIPolicyHandle policyHandle3 =
            // registry.winreg_OpenKey(policyHandle2,"wisemon",IJIWinReg.KEY_ALL_ACCESS);
            System.out.println("Printing first 1000 entries under HKEY_LOCAL_MACHINE\\BCD00000000...");
            for (int i = 0; i < 1; i++) {
                // String[] values = registry.winreg_EnumKey(policyHandle3,i);
                // Object[] values = registry.winreg_EnumValue(policyHandle3,i);
                Object[] values = registry.winreg_QueryValue(policyHandle2, "name", 100);
                Object[] values2 = registry.winreg_QueryValue(policyHandle2, "date", 100);
                System.out.println(new String((byte[]) values[1]));
                System.out.println(new String((byte[]) values2[1]));
            }
        } catch (UnknownHostException | JIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            System.out.println("Closing registry connection");
            registry.closeConnection();
        } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM