Article ID: 175948 - Last Review: March 29, 2007 - Revision: 3.7 INFO: Running Visual Basic Applications as Windows NT Services
This article was previously published under Q175948 On This PageSUMMARYMicrosoft does not currently recommend, and does not support, running Visual Basic applications as Microsoft Windows NT, Windows 2000 and Windows XP Services because the applications may exhibit unstable behavior when installed and run as Microsoft Windows Services. Microsoft Visual Basic 4.0 does not support callbacks nor is
Visual Basic 4.0 thread-safe. While Visual Basic 5.0 and 6.0 is apartment-model
thread-safe, there is no way to marshal calls back into a Visual Basic program
through the AddressOf operator. This behavior is by design. This article
includes some examples of this unstable behavior, a short explanation of the
possible causes of the instability, and a possible workaround.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) MORE INFORMATIONExamples of Unstable Behavior
Why This Unstable Behavior OccursA service in Microsoft Windows is a program that is written as a console application and runs whenever the operating system is running. Services are commonly employed to provide facilities such as directory replication, system activity auditing, process monitoring, or communications support.Services log on to Microsoft Windows NT, Windows 2000 and Windows XP under the LocalSystem account, which is a predefined local account used by system processes. A service that runs in the context of the LocalSystem account inherits these characteristics:
The Unattended EXE compile option available with Microsoft Visual Basic 5.0 and 6.0 does address the unexpected dialog problem, but thread safety remains an issue. Visual Basic 5.0 and 6.0 is apartment-model thread- safe unless or until a program uses the AddressOf operator. There is currently no way for Visual Basic to marshal multiple calls back into a Visual Basic 5.0 or 6.0 application through the AddressOf operator. Therefore, we do not recommend installing a Microsoft Visual Basic application as a Microsoft Windows NT Service. Other TechnologiesDevelopers can expect difficulties with efforts to employ Microsoft technologies such as ODBC, DCOM, OLE Automation, and DAO in a Microsoft Windows Service written in Microsoft Visual Basic. For this reason, and for those reasons already noted, Microsoft advises developers to avoid using these technologies in a Microsoft Windows NT Service written in Microsoft Visual Basic.REFERENCES For more information, see the following directory on MSDN:
\Platform SDK\Windows Base Services\Executables\Services
For more information, refer to the following book: Francesco Balena Programming Microsoft Visual Basic 6.0
(http://www.microsoft.com/mspress/books/2454.aspx)
, Microsoft Press, 2001 For additional information, please click the article numbers
below to view the articles in the Microsoft Knowledge Base:
198607
(http://support.microsoft.com/kb/198607/EN-US/
)
PRB: Access Violation in VB Run Time Using
AddressOf170883 (http://support.microsoft.com/kb/170883/EN-US/ ) HOWTO: Use NTSVC.OCX from Visual Basic 150777 (http://support.microsoft.com/kb/150777/EN-US/ ) INFO: Descriptions and Workings of OLE Threading Models 137890 (http://support.microsoft.com/kb/137890/EN-US/ ) HOWTO: Create a User-Defined Service APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
