利用API把自己注册成服务就行了吧

解决方案 »

  1.   

    不是要这样的服务,而是作为系统的一部分的服务,如同SQL Server 和IIS这样的服务
      

  2.   

    用API函数:CreateService
    Public Declare Function CreateService Lib "advapi32.dll"  Alias "CreateServiceA" ( _
      ByVal hSCManager As Long, _
      ByVal lpServiceName As String, _
      ByVal lpDisplayName As String, _
      ByVal dwDesiredAccess As Long, _
      ByVal dwServiceType As Long, _
      ByVal dwStartType As Long, _
      ByVal dwErrorControl As Long, _
      ByVal lpBinaryPathName As String, _
      ByVal lpLoadOrderGroup As String, _
      lpdwTagId As Long, _
      ByVal lpDependencies As String, _
      ByVal lp As String, ByVal lpPassword As String) As Longc范例:
    VOID CreateSampleService() 

        LPCTSTR lpszBinaryPathName = 
            "%SystemRoot%\\system\\testserv.exe"; 
     
        schService = CreateService( 
            schSCManager,              // SCManager database 
            "Sample_Srv",              // name of service 
            lpszDisplayName,           // service name to display 
            SERVICE_ALL_ACCESS,        // desired access 
            SERVICE_WIN32_OWN_PROCESS, // service type 
            SERVICE_DEMAND_START,      // start type 
            SERVICE_ERROR_NORMAL,      // error control type 
            lpszBinaryPathName,        // service's binary 
            NULL,                      // no load ordering group 
            NULL,                      // no tag identifier 
            NULL,                      // no dependencies 
            NULL,                      // LocalSystem account 
            NULL);                     // no password 
     
        if (schService == NULL) 
            MyErrorExit("CreateService"); 
        else 
            printf("CreateService SUCCESS.\n"); 
     
        CloseServiceHandle(schService); 
      

  3.   

    微软提供了一个可以用VB建立NT/2000下服务程序的控件,这里下载
    http://www.applevb.com/sourcecode/nt_server.zip
    不过微软并不推荐用VB做服务程序
      

  4.   

    NT Service sample Control Programhttp://smsoft.chat.ru