Update: September, 1997: Now that MSDN Online is free (after registering), you can obtain the source code for free.
Update: March, 1998: The above link keeps changing courtesy of Microsoft (the link now works as of 3/2/98). Also, the link to the source on the page has an error (a space before the .EXE) which makes it rather difficult to download. If you are interested in the source (which includes the documentation) or the compiled OCX, just click away! I promise not to change my links.
Next, once you get the source code, you have to make the OCX. That's right, VB Kids, you get the Visual C++ source code, but you don't get the OCX (I think this was done to make us Visual Basic developers sweat since we normally have it easier than Visual C++ developers). But wait! All you have is Visual C++ 5.0? It won't compile without some tweaking (I had a friend of mine fix it). An AVB reader noted, "All it took was to change a variable called 'default' (which is now reserved) to something else, e.g. 'def'". If you have Visual C++ 4.0, you'll be okay.
Now that you have the ActiveX control, NTSVC.OCX, just plop it on one of your forms, follow the excellent documentation, and you're set. It really only takes 10-15 lines of code to get it going and is very straight forward, even if you have never dealt with SRVANY or developing a Visual C++ service application. Like I said, the hardest part of this method is getting the OCX. Should Microsoft make this OCX available for re-distribution, it will be here. The key word there is "should" :)
VB Source Code
Strike three for Microsoft? With SRVANY, each user supposedly needs a NT Resource Kit License. With the OCX, you need a MSDN Library subscription. Both methods cost money. This third method is completely free! The source code is entirely in Visual Basic 5.0 using callbacks and the Win32 API. The code and documentation is all on-line in a Microsoft Knowledge Base article. It's free to get, and free to use. So, what's the catch this time (there's always a catch)?
The catch? I'm so glad you asked. Just read the Knowledge Base article. It's article Q175948. Here's an excerpt:
Microsoft does not currently recommend running Visual Basic applications as Microsoft Windows NT Services because they may exhibit unstable behavior when installed and run as Microsoft Windows NT Services. Microsoft Visual Basic 4.0 does not support Callbacks and neither Microsoft Visual Basic 4.0 or Microsoft Visual Basic 5.0 is thread-safe. This behavior is by design.
There you have it! The article goes on to give you the complete source code (in Visual Basic 5.0) to pull it off. It's interesting that Microsoft starts off telling you it is such a bad idea, but then has complete source code to do it. The article does state the nasty things that can happen (all very minor, in my opinion) when using this method, and does state a work around -- using the ActiveX control as stated above.
While Microsoft recommends against using the Visual Basic 5.0 method of turning your application into a service, it's actually better than using the ActiveX control. The reasons are because you have total control over the source code, and you don't have to manage a separate (difficult to understand) Visual C++ project. Just play it safe, and your Visual Basic application shouldn't encounter any problems when running as a service. There are some good tips in the Microsoft Knowledge Base article, such as making your application non-interactive, and reporting errors to the NT event logs or your own log files. Should you need to interact with your service application, create a separate application as many other services have done (WebSite, IIS, WebBoard, SQL Server, and many other mail, FTP and chat servers).
SpyWorks 5.0
Lastly, I have included a method that I'm afraid I know very little about. Daniel Appleman's company, Desaware, recently released an update to their popular Visual Basic add-on called "SpyWorks". SpyWorks, like Dan's popular Visual Basic books, allows Visual Basic developers to take their applications places they never could before.
An addition to SpyWorks 5.0, Dynamic Export Technology allows you to export functions from your Visual Basic created ActiveX DLL's. With this technology, Visual Basic developers can create export function libraries, control panel applets, Internet ISAPI filters, and make true NT Services.
I have not had time to explore this last method, but I thought it would be better to mention it than to not mention it at all. If I had to guess, I would say that SpyWorks 5.0 will allow you to achieve results similar to using the Visual Basic source code, or perhaps more stable such as the ActiveX control. Give it a try and let me know how it works out for you!
Services: Part II
Whew! Needless to say, there are now many ways to turn your Visual Basic 4.0 and 5.0 applications into Windows NT services. The method you decide to choose is up to you, but my recommendation is to use the ActiveX control or take your chances by using the Visual Basic source code.
I hope you found this information useful. It is provided for free to readers of the Advanced Visual Basic web site. Reproduction in whole or part is prohibited. Your comments and feedback are welcome, however I'm afraid that I cannot provide technical support for any of the methods or products mentioned. Please contact Microsoft technical support, search their knowledge base for help, or check out VBChat.