Results 1 to 7 of 7

Thread: Launching a VBscript from a Java program

  1. #1
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Launching a VBscript from a Java program

    I'm having some problems launching a VBscript from within a Java program under Windows. I get the following in my log file:

    Code:
    #Wed May 28 16:37:27 BST 2008 Event 26910: java.io.IOException: CreateProcess: %SystemRoot%\System32\wscript.exe "D:\Program Files\xxx\abc.vbs" "D:\Program Files\xxx\abc.vbs.txt" error=2
    Essentially i'm trying to launch the VBscript (which requires an argument - the TXT filename) via 'wscript.exe'. I'll have to check if I am permitted to publish the code snippet as it's a sensitive project. However, I was hoping someone could either shed some light on how to launch a Windows program from within Java and/or the meaning of 'error=2'. I have a feeling that it is related to a 'file not found' type of error but the VBS file definitely exists. My VBS script takes the argument supplied to it and creates a file for output from that argument. Perhaps the Java program is unable to decode the path to wscript.exe as I have used an environment variable to locate the Windows system root directory? Or could it be the backslashes in the path?

    I have quoted the vbscript file and its argument as these contain spaces. The command runs find from a DOS prompt.

  2. #2
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Launching a VBscript from a Java program

    2 means filenot found as you said.

    how are you invocing this?

    take a look at:
    When Runtime.exec() won't - Java World
    throw new ArgumentException (String, String, Exception)

  3. #3
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Re: Launching a VBscript from a Java program

    We figured out what the problem was. We were trying to launch the vbscript file using wscript. But were were trying to use an environment variable to get to the wscript program.

    i.e. we were launching using the following command line (from within the Java program):

    Code:
    &#37;SystemRoot%\system32\wscript.exe <vbscript_file> <argument>
    It appears that the %SystemRoot% environment variable is not valid. We hardcoded the command line to:

    Code:
    c:\windows\system32\wscript.exe <vbscript_file> <argument>
    and the vbscript program launched correctly and worked. However, we cannot rely on wscript.exe being in c:\windows\system32 (and hardcoding this path would be awful prgramming practice anyway!). What we need from within our Java program is a way to determine the path to the windows directory.

    Does anyone know how to do this (in Java)?

  4. #4
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Launching a VBscript from a Java program

    surely system32 is in the path environment variable?

    that is to say, any exe in it will be located. Might not be the nicest solution, but just ommiting the c:\windows\system32 might well work fine. It did under the old ms runtime.... but this was some time back mind.

    as did this little nugget.
    System.getProperty("user.home"));
    throw new ArgumentException (String, String, Exception)

  5. #5
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Re: Launching a VBscript from a Java program

    ^ Yes, that worked! We just launch 'wscript.exe' with no path and it runs! Thanks for that. What a schoolboy error on my part for not trying that to start with and trying to overcomplicate things unnecessarily.

  6. #6
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Launching a VBscript from a Java program

    no actually you where doing the 'right' thing.

    letting something determine its location via PATH is bad. Mainly because you've no garanettes it will be the same. And when something changes its not remotely obvious what the problem is. Also if some tit adds something called wscript to the winnt folder, thats different (or anything higher up in the PATH higherachie) you get very hard to trace issues.

    The 'propper' way would be to determine the system32 folder via api calls, have you use JNI before? (i can't belive there isn't a simpler way, but google shows nothing, however i've not java'd for like 5 years! C# just copied everything that was good, and fixed so much).

    Also where are my thanks bitch.
    throw new ArgumentException (String, String, Exception)

  7. Received thanks from:

    Taz (29-05-2008)

  8. #7
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Re: Launching a VBscript from a Java program

    ^ LOL! There you go.

    We did look at using getenv() but that has been 'deprecated' in the 1.4.2 JRE that we're using. It's actually worse than that, it doesn't work! It does seem particularly difficult to get Windows environment variables from within Java.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. please urgent help needed with c++ program
    By haelly in forum Welcome to HEXUS!
    Replies: 2
    Last Post: 19-12-2007, 11:02 PM
  2. Replies: 16
    Last Post: 11-12-2007, 05:40 PM
  3. I.M.P.L (Java / DirectShow question)
    By Purple in forum Software
    Replies: 2
    Last Post: 15-08-2005, 05:09 PM
  4. ATi + Java + BSOD?
    By Kezzer in forum PC Hardware and Components
    Replies: 1
    Last Post: 11-06-2005, 01:26 PM
  5. Dial-up program help.
    By Anders in forum Software
    Replies: 4
    Last Post: 04-09-2003, 02:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •