Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Win32_ShortcutFile重命名文件名-WMI架构方法重命名和_Java_Wmi_Jacob - Fatal编程技术网

Java 如何使用Win32_ShortcutFile重命名文件名-WMI架构方法重命名和

Java 如何使用Win32_ShortcutFile重命名文件名-WMI架构方法重命名和,java,wmi,jacob,Java,Wmi,Jacob,作为一名Jacob新手,我无法使用Win32_ShortcutFile模式的重命名方法来更改文件名。我只想通过模式方法调用来使用它。请建议我应该如何进行 我的代码如下所示: public static void main(String[] args) { ComThread.InitMTA(); ActiveXComponent os = null; try { ActiveXComponent wmi = new ActiveXComponen

作为一名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();
    }

}
publicstaticvoidmain(字符串[]args){
ComThread.InitMTA();
ActiveXComponent os=null;
试一试{
ActiveXComponent wmi=新的ActiveXComponent(“winmgmts:\\\”;
字符串newName=“jacobtest”;
Variant instances=wmi.invoke(“InstancesOf”、“Win32_ShortcutFile”);
Enumeration en=新的EnumVariant(instances.getDispatch());
while(en.hasMoreElements()){
ActiveXComponent bb=新的ActiveXComponent(en.nextElement()
.getDispatch());
String file=bb.getPropertyAsString(“文件名”);
System.out.println(文件);
if(file.equals(“文件名”)){
os=新的ActiveXComponent(en.nextElement().getDispatch());
调用(“重命名”,newName);
}
}
}
最后{
ComThread.Release();
}
}
我终于明白了……)

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

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