Calling an .exe file in VB

Posted on 2005-03-05
Medium Priority
Last Modified: 2010-05-02

We have a Java program called Test that has a textbox on it.  The user would enter a path and then press the Enter key.  The path will then be used to process other commands in the application.  

Now, we converted our Java application into an .exe file.  We then want to call this file in a VB application by using Shell.  Our syntax goes like this:

a = Shell("Test.exe")
AppActivate a
SendKeys "C:\TestFile.pdf"
SendKeys "{Enter}"

The textbox (in the Java app) receives the focus when the program is loaded.  However, the program doesn't work.  What do I need to make it work?

Thanks in advance!

Question by:akeena_g
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

plq earned 600 total points
ID: 13465368
Wouldn't it be better to make your EXE accept a command line argument

Then you can do

a = Shell("Test.exe C:\TestFile.pdf")

sendkeys is considered bad programming, and often leads to problems and unreliability
LVL 17

Expert Comment

ID: 13465491
I would go with plq's suggestion with one small addition, if you had a long file names it is better to use double quotes:

a = Shell("Test.exe ""C:\TestFile.pdf""")

Author Comment

ID: 13468900
How exactly can I make my exe prog accept a command line argument?

Expert Comment

ID: 13469264
try following

  ReturnValue = Shell("NOTEPAD.EXE", 1)
  AppActivate ReturnValue
  SendKeys "Hello"
  SendKeys "{Enter}"

hope it helps,

LVL 22

Assisted Solution

JesterToo earned 600 total points
ID: 13469325
I am assuming it is still a Java app and was converted to a windows exe by something like "exe4j".  If so, you just need to add some code to your main method in the startup class module like this:

         public class Appname {
           public static void main (String[] args) {
               if (args.length < 1) {
                  System.out.println ("usage: Appname <filename>");
            } else {
                  String fileName = args[0];
               yada yada yada...

replace the existing logic that expects the filename to be entered on screen.  


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question