Solved

Program Launching

Posted on 2000-04-23
7
305 Views
Last Modified: 2013-11-27
what is the programming code I need in order to launch an application (such as Microsoft Money) from the program I am creating?
0
Comment
Question by:newWag
  • 3
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
GivenRandy earned 50 total points
ID: 2742330
Use the Shell() function.  For example:

Shell "C:\Program Files\Microsoft Money\System\MSMONEY.EXE"
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 2743687
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.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2744180
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:BarryTice
ID: 2745449
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.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2746265
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
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 2747385
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.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2747471
Barry, I tried this and it worked fine on my system.  There must be a difference in the configuration somewhere.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now