Link to home
Start Free TrialLog in
Avatar of newWag
newWag

asked on

Program Launching

what is the programming code I need in order to launch an application (such as Microsoft Money) from the program I am creating?
ASKER CERTIFIED SOLUTION
Avatar of GivenRandy
GivenRandy

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 TSO Fong
I've found Shell to be a bit flaky, newWag. GivenRandy is correct that it's the command to use, but instead of calling as s/he shows, I find you need to do something like this:

strPath = "C:\Program Files\Microsoft Money\System\MSMONEY.EXE"   'or whatever your path is

If InStr(strPath, " ") <> 0 then
    Shell Chr(34) & strPath & Chr(34)
Else
    Shell strPath
End If


My experience is that if there is a space in the path, even when called as GivenRandy shows, the shell only recognizes the path up to the first space. Above, it would try to call "C:\Program" and pass the remainder of the line as a parameter to "Program".

To complicate things, if there are no spaces in the path, Shell returns an invalid call error if you do includes surrounding quote marks. Go figure.

Alternately, you can convert all your paths to short file names before calling Shell, if you want to set up the API to do so.

Hope this helps. -- b.r.t.
Barry:  Does this happen in any pariticular instance?  I'm asking because I have used Shell with no quotes for long pathnames and so-far have had no problems.  I have seen the problem when I pass parameters to the program that I'm shelling.  There I've had to use quotes.
I have been passing parameters at times, but other times I haven't.

The problem has only shown up for me when I've had a space in the path name. For example, if I run a vb app I'm working on, say
 c:\My Documents\VB Apps\app.exe

my experience is that shell tries to run C:\My.

Maybe I'm just exceptionally unlucky, or maybe I have a screwy installation going. (There have been other things that seem like they should work that don't, so I make no promises.)

But the only way I've been able to get things to work consistently is as above. Any time there is a space in the path, it has not worked for me unless I've forced quotes onto each end of the string. And any time there's been no space in the path, quotes have made it throw back an error.

Long file names vs. short file names doesn't seem to make any difference -- as long as there are no spaces. I've had no trouble shelling something like

c:\BigFolder\AnotherBigFolder\Whats_In_Here\Another_subdirectory\app.exe"
without quotes.

Therefore, I always use an InStr() conditional, as above. If I'm passing parameters, the quotes go around the file path, but not around the parameters.

If InStr(strPath, " ") <> 0 Then
    Shell Chr(34) & strPath & Chr(34) & " " & strParameters
Else
    Shell strpath & " " & strParameters
End If

Does this make any sense, or do I just have a screwed up machine?
-- b.r.t.
It's probably always safer to use the quotes, as maybe different installations will act differently???

This worked for me:

Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe", vbNormalFocus
Yes, Paul. But would this work?

strPath = "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe"
Shell strPath, vbNormalFocus

This is where I've always had problems, when the path to shell is indicated by a variable.
Barry, I tried this and it worked fine on my system.  There must be a difference in the configuration somewhere.