Solved

COM object as NT Service

Posted on 2002-03-04
15
200 Views
Last Modified: 2010-05-02
I have a COM object that reads a directory for a specific file and if it finds one, it is to copy it from one folder to another.
I want this COM object to a be an NT Service that runs every 10 minutes....how can I make this COM object an NT Service so it runs in the background...like other Services on a machine?
0
Comment
Question by:lobos
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6839260
I would write a small VB app that runs as a service, and that calls this COM object.
* to run every 10 minutes: use a timer control or a API, as you like
* to run as service: use the ntsvc.ocx, or some utility to transform your application into a service.


Note:
  For simplicity, you might use the timer control and the ntsvc control on the same form, the utility to transform your application makes it more difficult in your code to handle the different events send from the services applet...

CHeers
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6839269
Well, VB executables don't really have the proper interface to be installed as services by themselves.

What you need to do is download this C program that can act as a "proxy" for your VB program.  So, the C program is actually the one that runs as the NT Service, but when it starts up, you give it some start-up parameters to start-up your VB program.

This program was available on the MSDN disks.... let me see if I can find in out there.....

Here is one of the links that I used:

http://www.geocities.com/SiliconValley/Pines/3991/nthowto.htm

Here is the other one I think:

http://vbwire.com/advanced/howto/service.asp

Good Luck!
0
 
LVL 4

Expert Comment

by:srauda
ID: 6840172
I believe the NT Service Toolkit by Desaware is exactly what you are looking for.  I have used it and it works very nicely and is very reliable.

This toolkit allows you to create an ActiveX Dll that is linked to an exe created by the toolkit.  The exe runs as the service and calls your dll for running the tasks you require.  The exe hides all the complexities required for creating a service.

Check it out at www.desaware.com
0
 
LVL 18

Accepted Solution

by:
mdougan earned 100 total points
ID: 6843104
srauda,

That is exactly what the srvany.exe does that you can download for free from the links I provided above.  The links also provide sample VB source, including some important tips on code necessary for cleanly terminating the service when the user stops the service using the Service control manager.

Why pay for something from Desaware when you can get it for free?
0
 
LVL 4

Expert Comment

by:srauda
ID: 6844334
mdougan,

the srvany.exe is not as stable.

0
 
LVL 4

Expert Comment

by:srauda
ID: 6844338
Plus, you cannot handle events passed on by the service control manager if necessary.
0
 

Author Comment

by:lobos
ID: 6844386
I would like to avoid including other vendors for anything.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Expert Comment

by:srauda
ID: 6844712
then mdougan has the right solution.

another solution would be to include the COM in a standard exe.  Then have the Microsoft Task Scheduler run the exe every ten minutes.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6845542
I never had any trouble with srvany.exe.  

I'm not sure what you mean by events.  srvany handles the user starting or stoping the service from the service control manager (and as far as I know, anthing else you can do in the service control manager), all you have to do is put code in your vb component for when those events are relayed to your app from srvany.
0
 
LVL 4

Expert Comment

by:srauda
ID: 6845717
In the desaware toolkit, have a scm object reference that you can use to respond to start and stop events as well as user control events.

I never saw how my vb code could respond to srvany.  As far as I saw, srvany would be responsible for launching and terminating your executable.  In fact, your program had to be an executable.

Maybe I am mistaken, but that was how I saw it.

0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6851778
I'll return shortly, but since I've asked Administration to contact lobos, wanted to include this first.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20258729.html
http://www.experts-exchange.com/questions/Q.20269575.html
http://www.experts-exchange.com/questions/Q.20273076.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link, entitled EXPERTS WHO ARE TIRED OF ABANDONED QUESTIONS CAN HELP"  ... http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Thank you everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6869725
A "C" grade without even a comment as to why?  Please do make a comment to tell us why.  This not only helps the experts here understand, but also future people who visit this item in our PAQ for help.  If you've found more in this regard, please add it. If the grade was given in error, let us know, we can correct.

The points to you are the same, but the expert points which flow depend on the grade.

Thanks,
Moondancer - EE Moderator
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6869979
After re-reading this the 3rd time and still no response, feel that an A is in order and changed it accordingly.
Moondancer - EE Moderator
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6872867
Thanks!  I can't understand a "C" either, he got more than enough information to answer his original question.
0
 

Author Comment

by:lobos
ID: 6876796
I applogize, it was an error and it should have been corrected, thanks for changing it for me.
Thanks again.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now