Solved

How to run a another application in sync.

Posted on 2002-07-26
10
241 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
10 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 150 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
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!

 
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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
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…

685 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