Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Program Launching

Posted on 2000-04-23
7
Medium Priority
?
399 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 150 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
This collection of functions covers all the normal rounding methods of just about any numeric value.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…
Suggested Courses

886 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