Solved

How to run a another application in sync.

Posted on 2002-07-26
10
237 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now