Link to home
Start Free TrialLog in
Avatar of nobleone
nobleone

asked on

vb.net program launchs and then closes automatically

I have developed a vb.net program which when run from a shortcut works fine, however when I run it through an older vb6.exe which uses the winapi Shell Execute function, the program briefly appears on the screen and then closes.   This also happens with a piece of third party software that is setup to run this program.  
Developed in Visual Studio 10, vb.net, this happens on Windows 7 and Xp workstations.  The program is configured as a Windows Form Application.
Would appreciate any help

vb6 code that does the shell to the vb.net exe
' First, create a known, temporary HTML file
exeName = Space(255)

retval = FindExecutable(FileName, Dummy, exeName)
exeName = Trim(exeName)

' If an application is found, launch it!
If retval <= 32 Or IsEmpty(exeName) Or Err Then  ' Error
    LaunchFile = False
Else
    FileName = quo(FileName) 'put quotes around the item
    retval = ShellExecute(frmIcon.hwnd, "open", Trim$(exeName), FileName, Dummy, 5)
    If Err <> 0 Then
        MsgBox "Unable to run program <" & exeName & "> and launch file <" & FileName & "> RetVal=<" & CStr(retval) & "> Error=<" & Error$ & ">"
    Else
        LaunchFile = True
    End If
End If
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

What is in "Dummy"?  You may need to pass in the working directory instead (often the path to the executable itself) for the app to work correctly.
Avatar of nobleone
nobleone

ASKER

Dummy is empty string...good point, I am going to try changing that and see if it works...will get back to you
I solved the problem....the code was using application.run to run the first form from the  Sub Main used on startup as recommended in reading I did.  When run from a shortcut on desktop no problem, when shelled in any way, causes the program to self terminate.  I changed this to  form.showdialog method and it solved the problem.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

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
vb6 conversion is why,   had about 800 properties, ocx , etc changes, definitely a learning experience...but vb.net is much better than the old vb6..thats for sure...did not know about the application.startup...I've been a sub main guy from years back...suspect that would have solved this problem also.  
I've requested that this question be closed as follows:

Accepted answer: 0 points for nobleone's comment http:/Q_27414103.html#37104441

for the following reason:

was not the solution, but appreciated the very prompt input
mistake in the clicking...I wanted to close and award to idle_mind...was on my comment when I clicked close by accident, can you please award him the points...thanks
Not the exact solution, but would have solved the issue also