作为Jacob新手,我无法使用Win32_ShortcutFile架构的重命名方法来更改文件名。我想通过只调用schema方法来完成它。请建议我该如何继续。
我的代码如下所示:
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();
}
}
答案 0 :(得分:0)
最后我明白了...... :)
重命名文件时出现轻微错误,应如下所示:
String newName = "D:\\jacobtest.docx";
if (file.equals("filename")) {
os = new ActiveXComponent((en.nextElement).getDispatch());
os.invoke("Rename", newName);
}