如何在 Java 中执行 VBS 脚本?他首选的方式是什么?我在网上找到了很多建议,所以我不知道什么更好......
1.
Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
2.
Runtime.getRuntime().exec("wscript.exe " + file.getPath())
3.
String script = "C:\\work\\selenium\\chrome\\test.vbs";
String executable = "C:\\windows\\...\\vbs.exe";
String cmdArr [] = {executable, script};
Runtime.getRuntime ().exec (cmdArr);
4.
Runtime.getRuntime().exec("cmd /c a.vbs");
5.
Desktop#open(new File("c:/a.vbs"));
这还不是全部。
这个选什么好?我需要执行以下脚本:
If Not IsObject(application) Then
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"