Link to home
Start Free TrialLog in
Avatar of kumarbabu
kumarbabuFlag for United States of America

asked on

use of shell command in Visual Basic Express 2008

I am writing a program in Visual Basic Express 2008. I need to call an executable using a button click. I have two buttons in the program. . Somehow the executable does not seem to run. If I run the executable from the command line it always works and throws up a menu in the screen. When called from my visual basic program nothing shows up the screen. What am I doing wrong? The second button which calls calc.exe always works.The code is shown below. If I replace the content of the shell for button1_click with the pathname for calc.exe, then that runs.
Public Class mgmt_suite
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MgmtSuite.Click
        Shell("C:\L1Applications\bin\L1-IMS", AppWinStyle.MaximizedFocus)
    End Sub
 
    Private Sub Global_traveler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Global_Traveler.Click
        Shell("C:\Windows\System32\calc.exe")
    End Sub
 
    Private Sub mgmt_suite_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of buzzle74
buzzle74

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kumarbabu

ASKER

Hi buzzle74,

Thanks for your solution. It was very helpful. However, for some reason the solution proposed works when I call other executables. However, it does not seem to work for the particular executable "L1Applications\bin\L1-IMS"; This application runs by itself without any problem but I can't seem to use VB to call it. Any ideas on why this particular application is unresponsive to a call from VB?

Thanks,
By setting
System.Environment.CurrentDirectory = "C:\L1Applications\bin\" before the Process.Start line the software was able to be launched. The problem is now solved.
Avatar of Mike Tomlinson
You need to set the WorkingDirectory first:

        Dim p As New Process
        p.StartInfo.FileName = "C:\L1Applications\bin\L1-IMS"
        p.StartInfo.WorkingDirectory = "C:\L1Applications\bin\"
        p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
        p.Start()