Using DDE to Check If Another Windows Application Is Open

Last reviewed: April 30, 1996
Article ID: Q108681
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b

When you are using dynamic data exchange (DDE) commands programmatically, there may be times when you have to determine if a session of an application is already running. DDESetOption() and DDEInitiate() can be used determine if a application is running or not.

For example, the following code determines if Microsoft Excel is already open:

   =DDESetOption("Safety",.f.)         && This turns off the message box
                                       && so that the program will
                                       && not be interrupted.
   openapp=DDEInitiate("Excel","System")

   IF openapp < 0                       && Any negative number returned
                                        && by DDEInitiate() means that a
                                        && channel could not be opened.
      RUN/N C:\EXCEL\EXCEL.EXE
   ENDIF


Additional reference words: VFoxWin 3.00 FoxWin 2.50 2.50a 2.50b
KBCategory: kbinterop kbprg
KBSubcategory: FxinteropDde


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.