Solved

Program Launching

Posted on 2000-04-23
7
315 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

930 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

10 Experts available now in Live!

Get 1:1 Help Now