Start Windows program from NT service

Source: Internet
Author: User
Tags ini

Introduced

Typically, the NT service is a console application, which does not have a message loop. The NT service can start without waiting for the user to log on to the computer, and it will not stop running after the user logs out. However, many existing ActiveX controls are difficult to use in console programs at times.

On the other hand, MFC and VB programs are Windows applications, so it is fairly straightforward to use ActiveX controls in MFC or VB programs. It would be nice to make MFC and VB programs work like NT services:

• Start before the user logs on to the computer

• Continue running after the user has logged out of the computer

You can write NT services directly in the form of a Windows program, but this article provides a simpler solution. The source code of this article is a simple NT service program, it can start and close other programs. All you need to do is install this service and modify the. ini file. The following are the benefits of using this NT service.

• It can start any number of programs you specify. Programs that are started will run like NT services (for example, they run in the background without the user logging on to the machine).

• In the absence of appropriate privileges, a user cannot terminate a program started by this service (unless the machine shuts down).

• You can test and debug your programs outside of NT services. For example, you can run your program in the DevStudio debugger, step into the source code to find errors, and so on. When debug is error-free, you configure it as a product, starting it from NT services.

Xyntservice

XYNTService.exe is the name of this NT service executable file. It is part of the client-server development tool I developed. You can use and modify the source code included in this article for free. I know there are other tools that offer almost the same functionality as Xyntservice. However, as you can see, Xyntservice has more features and is easier to use (for example, you don't need to edit the registry). The following shows how to use this program.

• To install (install) service, run the following command at a command prompt: Xyntservice-i

• To uninstall (Un-install) service, run the following command at a command prompt: Xyntservice-u

By default, when the computer restarts, the installed service starts automatically. You can also use the service icon to start and close the service from the Control Panel. When the service starts, it will create all processes defined in the Xyntservice.ini file one by one. When the service shuts down, it terminates these processes (in reverse order). The Xyntservice.ini file should be placed in the same directory as the executable file. Here is an example of this file.

[Settings]
 ServiceName = XYNTService
 ProcCount = 3
 CheckProcess = 30
  [Process0]
 CommandLine = c:\MyDir\XYRoot.exe
 WorkingDir = c:\MyDir
 PauseStart = 1000
 PauseEnd = 1000
  UserInterface = Yes
 Restart = Yes
 [Process1]
  CommandLine = c:\MyDir\XYDataManager.exe
 WorkingDir = c:\MyDir
 PauseStart = 1000
 PauseEnd = 1000
  UserInterface = Yes
 Restart = Yes
 [Process2]
  CommandLine= java XYRoot.XYRoot XYRootJava.ini
 UserInterface = No
 Restart = No

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.