Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running program as a service

Status
Not open for further replies.

tvbruwae

Programmer
Aug 9, 2001
224
EU
Hi

I have a VB .NET Windows application that I would like to implement as a Windows service. Basically there are two scenario's:

1) The .exe file is executed normally. This is done manually and shows a Windows form, allowing the user to interact with the program
2) The .exe file is started with a parameter. In that case only some code is executed. No forms or dialogs are shown.

I would like the second type to be implemented as a service. As such I have two questions:

a) What is the best way to do this? Personally I would use srvany.exe to implement the .exe with the parameter as a service, but maybe there are newer (and better) ways nowadays?

b) How do you "loop" your code in VB .NET? If the .exe is started once (as a service) it should still perform the encoded algorithm regularly, e.g. every hour. So I assume that the entire code block needs to be put into a loop with a "sleep" at the end?

Thanks for any tips!
Tim

 
tvbruwae,

Not all Windows programs run in a window and provide an interface to the user. Instead, some programs run as services. Services generally run behind the scenes in a system context and do not provide interaction with the desktop (although some do).

The Instsrv.exe tool included in the Windows 2000 Resource Kit as well as Windows Server 2003 Resource Kit is a command-line tool that lets you install an application as a Windows service. With Instsrv.exe, you specify the location of the application's executable, the name you want to assign to the service, and the credentials will run under. You can also use the Remove argument to remove a service. See the Resource Kit Help documentation for other syntax notes.

If you prefer a GUI-based method, turn to the Srvinstw.exe wizard, also included with the Resource Kit. This wizard provides a graphical interface for adding and removing services and device drivers on the local computer and on remote computers.

For your second question, there are many alternatives better than loop. You may use threads, asynchronous processing or event notification based system.

 
Thanks for your reply. I managed to use instsrv.exe to run the tool as a service, so that part is solved.

As for the loop, I replaced it with a timer control that executes the algorithm. It still doesn't work as expected though, so I hope to get this working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top