tags:

views:

69

answers:

2

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 account to
   Dim obDomain
   Set obDomain = obApp.Domains.ItemByName("yahoo.com")

   Dim obAccount
   Set obAccount = obDomain.Accounts.Add

   ' Set the account properties
   obAccount.Address = "[email protected]"
   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?

+2  A: 

.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();
Thomas Lötzer
A: 

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

mkolodziejski
or maybe for generic use - let Windows handle the file:public final static String PATH = "rundll32 url.dll,FileProtocolHandler";File f = new File("C:\\Documents and Settings\\Dusk\\Desktop\\account.vbs");Process p = Runtime.getRuntime().exec(PATH + " " + f.getAbsolutePath());
mkolodziejski
It's working. Thanks!
Dusk