Being a Jacob newbie, I am not able to use rename method of Win32_ShortcutFile schema for changing filename. I want to use it done via schema method calling only. Please suggest how I should proceed.
My code looks like this:
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();
}
}
Finally I got it.... :)
Minor mistake while renaming the file, it should be as shown below: