gpt4 book ai didi

java - 无法从 java 启动 VB 应用程序

转载 作者:行者123 更新时间:2023-11-30 05:14:37 24 4
gpt4 key购买 nike

我尝试从 Java 启动 VB 应用程序,但遇到运行时错误:

Exception in thread "main" java.io.IOException: Cannot run program "C:\Documents and Settings\Dusk\Desktop\accounts.vbs": createProcess error=193, %1 is not  a valid Win32 application
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at check.main(check.java:8)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(NativeMethod)
at java.lang.ProcessImpl.<init><ProcessImpl.java:81)
at java.lang.ProcessImpl.start<ProcessImpl.java:30)
at java.lang.ProcessImpl.start<ProcessImpl.java:452)
... 1 more

这是我正在使用的java代码:

public class check{

public static void main(String[] args) throws Exception
{


ProcessBuilder pb = new ProcessBuilder("C:\\Documents and Settings\\Dusk\\Desktop\\account.vbs");
pb.start();
}
}

这是 vb 文件:

Dim obApp
Set obApp = CreateObject("hMailServer.Application")

' Authenticate. Without doing this, we won't have permission
' to change any server settings or add any objects to the
' installation.
Call obApp.Authenticate("Administrator", "password")

' Locate the domain we want to add the account to
Dim obDomain
Set obDomain = obApp.Domains.ItemByName("yahoo.com")

Dim obAccount
Set obAccount = obDomain.Accounts.Add

' Set the account properties
obAccount.Address = "white@yahoo.com"
obAccount.Password = "white"
obAccount.Active = True
obAccount.MaxSize = 100 ' Allow max 100 megabytes

obAccount.Save

为什么我是这个异常(exception),我该如何运行我的 Java 程序?

最佳答案

.vbs 文件不是 native 应用程序。尝试运行 start "C:\\Documents and Settings\\Dusk\\Desktop\\account.vbs" 而不是仅运行该文件。这将运行与该扩展名关联的默认应用程序,即执行与在资源管理器中双击该文件时发生的相同操作。所以那就是:

ProcessBuilder pb = new ProcessBuilder("start", "C:\\Documents and Settings\\Dusk\\Desktop\\account.vbs");
pb.start();

关于java - 无法从 java 启动 VB 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2041066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com