Microsoft KB Archive/129739

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

Article ID: 129739

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129739



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
 Start a new project in Visual Basic. Form1 is created by default. Add a new Module to the project by choosing Module from the Insert menu. Module1 is created by default.  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  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. 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: KB129739

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.