KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q129739: How to Determine If VB 4.0 App Was Launched as OLE Server

Article: Q129739
Product(s): Microsoft Visual Basic for Windows
Version(s): 
Operating System(s): 
Keyword(s): 
Last Modified: 11-JAN-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual Basic Standard Edition, 32-bit, for Windows, version 4.0 
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows, version 4.0 
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0 
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows, version 4.0 
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0 
-------------------------------------------------------------------------------

SUMMARY
=======

This article describes how to use the StartMode Property of the Visual Basic App
object to determine whether an application started as a stand-alone project or
as an OLE Automation object application.

MORE INFORMATION
================

If the StartMode property has a value of vbSModeStandalone (or 0), it means that
the application started as a stand-alone project. That is, the user started the
.EXE from File Manager or by double-clicking the icon from Program Manager.

If the StartMode property has a value of vbSModeAutomation (or 1), it means that
the application started as an OLE Automation object application. That is, the
.EXE started because an OLE Automation client called CreateObject.

These constants are listed in the Visual Basic object library in the Object
Browser.

At design time, you can debug an application as if it were started as an OLE
Automation object application by setting StartMode in the Project Options dialog
box to 1 (vbSModeAutomation) by selecting the OLEServer option button. But a
project's actual StartMode setting is determined by how that application is
started at run time, not by its nominal setting in the Project Options dialog
box when you create an executable (.EXE) file.

When StartMode is set to 1 and there are no public classes in the project, you
must use the End statement or choose End from the Run menu or toolbar to end the
application. If you choose Close from the Control menu, the form closes but the
project is still running.

Step-by-Step Example
--------------------

1. Start a new project in Visual Basic. Form1 is created by default.

2. Add a new Module to the project by choosing Module from the Insert menu.
  Module1 is created by default.

3. Copy the following code, and Paste it into the General Declarations portion
  of Module1:

     Public Sub main()
        If App.StartMode = vbSModeStandalone Then
           MsgBox "Application being started as a stand alone EXE!"
        Else
           MsgBox "Application being started as an OLE Automation server!"
        End If
     End Sub

4. In the Project Options dialog box (Choose Options from the Tools menu and
  then select the Project tab), choose Sub Main as the startup form and choose
  OLEServer as the startmode.

5. Press the F5 key to run the program. A message box will tell you that the
  application was started as an OLE Automation server.

Additional query words: 4.00 vb4win vb4all

======================================================================
Keywords          :  
Technology        : kbVBSearch kbAudDeveloper kbVB400Search kbVB400 kbVB16bitSearch

=============================================================================

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.

Copyright Microsoft Corporation 1986-2002.