Solved

Program Launching

Posted on 2000-04-23
7
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Technology Partners: 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

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

738 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