Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to run a another application in sync.

Posted on 2002-07-26
10
Medium Priority
?
246 Views
Last Modified: 2008-03-10
Hi all,
    I'm looking for a way to run a shell command (Linking to another .exe) in sync (i.e. my program will will not continue to execute until the other application ends).

    How can I also detect if my application (NOT the one I'm calling) is already running (since I only want one instance of it running ever)

    Thanks
0
Comment
Question by:DragonWolf
[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
10 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 450 total points
ID: 7179789
Here is a link to code that will shell and wait

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6071&lngWId=1

At the beginning of your app this code will check for a previous instance

if app.PrevInstance then
  msgbox "Already running"
end if
0
 
LVL 4

Expert Comment

by:gencross
ID: 7179796
Here is also a link to an EE PAQ with code that will execute and wait.  It may be a better way to go.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20270080
0
 
LVL 2

Expert Comment

by:selim007
ID: 7179857
dear,
declare the following function in a module:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

to execute any file use the following syntax from your project:
ShellExecute 0, "Open", "application_name.exe", "", "", vbNormalFocus

now to detect if your application is already running use the following piece of code in your sub main or startup form:

if App.PrevInstance then
  'another instance of this application is already running
  msgbox "application already running"
else
 'this is the only instance of this application
end if
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:gencross
ID: 7179889
selim007,

I'm not sure if you read the entire question.  The code you provided will execute an file, but it will not wait on that process to end before continuing.  

If you noticed the PrevInstance code you posted was already posted above.  Why duplicate comments?  Post if you have a different or an alternate way to do something, but not if you have identical code.

0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 7180299
Function MyFunc()
  Dim myObject As Object
  Dim RetVal As Variant
 
  Set myObject = CreateObject("WScript.Shell")
  RetVal = myObject.Run("c:\windows\notepad.exe", 1, True)
  MsgBox "Notepad is closed"

End Function


'TRue - wait until proc is over
'False don't wait
0
 
LVL 1

Author Comment

by:DragonWolf
ID: 7184808
How can I lock/end this question? I already figure this out.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7191046
You'll need to post a question to community support stating you would like to delete the question.  Give the question id as well as why you would like it deleted.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7191061
I am curious how exactly you figured this out?  The duplicate question you posted did not answer this question, but it answered another question you posted about DOS full screen problems.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7191081
The duplicate question also did not answer this question fully, but only one small portion of the question.  If you figured out the answer yourself then this question can be deleted, but if any of the comments that were made were helpful in helping you solve the problem then points need to be awarded.
0
 
LVL 1

Author Comment

by:DragonWolf
ID: 7193156
I solved the sinking problem myself.
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 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