【问题标题】:How to Rename fileName using Win32_ShortcutFile - WMI schema method rename and Jacob如何使用 Win32_ShortcutFile 重命名文件名 - WMI 模式方法重命名和 Jacob
【发布时间】:2013-09-10 11:39:54
【问题描述】:

作为 Jacob 新手,我无法使用 Win32_ShortcutFile 架构的重命名方法来更改文件名。我只想通过模式方法调用来使用它。请建议我应该如何进行。

我的代码如下所示:

    public static void main(String[] args) {
    ComThread.InitMTA();
    ActiveXComponent os = null;

    try {
        ActiveXComponent wmi = new ActiveXComponent("winmgmts:\\\\.");
                    String newName = "jacobtest";
        Variant instances = wmi.invoke("InstancesOf", "Win32_ShortcutFile");
        Enumeration<Variant> en = new EnumVariant(instances.getDispatch());

        while (en.hasMoreElements()) {
            ActiveXComponent bb = new ActiveXComponent(en.nextElement()
                    .getDispatch());
            String file = bb.getPropertyAsString("FileName");
            System.out.println(file);

            if (file.equals("filename")) {
                os = new ActiveXComponent(en.nextElement                                        ().getDispatch());
                os.invoke("Rename", newName);
            }

        }
    }

    finally {
        ComThread.Release();
    }

}

【问题讨论】:

    标签: java wmi jacob


    【解决方案1】:

    终于明白了.... :)

    重命名文件时的小错误,应该如下所示:

      String newName = "D:\\jacobtest.docx";
      if (file.equals("filename")) {
                os = new ActiveXComponent((en.nextElement).getDispatch());
                os.invoke("Rename", newName);
            }
    

    【讨论】:

      猜你喜欢
      • 2018-07-27
      • 2019-09-09
      • 2016-05-29
      • 2014-09-09
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      相关资源
      最近更新 更多