开发者

Unable to start VB application from java

I'm trying to launch VB application from Java, but I'm getting runtime error:

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

Here's the java code which I'm using:

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();
}
}

and Here's the vb file:

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 accou开发者_运维问答nt 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  

Why I'm that exception, and how can I run my Java program?


.vbs files are not native applications. Try running start "C:\\Documents and Settings\\Dusk\\Desktop\\account.vbs" instead of just the file. This will run the default application associated with that extension, i.e. do the same thing that happens when you double-click the file in the explorer. So that would be:

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


have You tried executing Your process as "wscript file.vbs" ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜