我在D7环境下,安装测试服务,运行正常。
脱离D7,就运行不正常了。
怎么回事呢?

解决方案 »

  1.   

    仔细检查你的代码吧.
    大牛用D7或CB6写的服务程序, 运行几年都没有问题.
      

  2.   

    满足会D7,同时又会BCB6,同时又是大牛
    想来想去,只有妖哥了,哈哈 
      

  3.   


    现在已经测试,找到症结:我用一个servicestart函数,启动后服务功能不完全执行,手动启动服务没有这个问题。
    代码如下 :能帮我看看怎么回事吗?function ServiceStart(const ServiceName: string; const Computer: PChar = nil): Boolean;
    {
      启动服务
    }
    var
      SCM, SCH: SC_Handle;
      P: PChar;
    begin
      Result := False;
      SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
      if SCM <> 0 then
      begin
        SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS);
        if SCH <> 0 then
        begin
          Result := StartService(SCH, 0, P);
          CloseServiceHandle(SCH);
        end;
        CloseServiceHandle(SCM);
      end;
    end;
      

  4.   

    现在发现好像是安装的有问题。手工安装是执行:cmd.exe /c service.exe/install  
    因为我的服务里面带有两个timer,需要启动。让程序安装服务,timer就是启动不起来。
      

  5.   


    function InstallService(SvcName, SvcDispName, SvcFullPath: string): integer;
    var
      hSCM, hService: SC_HANDLE;
      sInfo: string;
      P: PChar;
    begin
      result := 0;
      hSCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
      if hSCM = 0 then
      begin
        result := GetLastError;
        exit;
      end;
      try
        hService := CreateService(hSCM,
          PChar(SvcName),
          PChar(SvcDispName),
          SERVICE_ALL_ACCESS, //SERVICE_START OR SERVICE_QUERY_STATUS OR _DELETE,
          SERVICE_WIN32_OWN_PROCESS,
          SERVICE_AUTO_START, //SERVICE_DEMAND_START, //SERVICE_AUTO_START,
          SERVICE_ERROR_NORMAL,
          PChar(SvcFullPath),
          nil, nil, nil, nil, nil);    if hService = 0 then
        begin
          result := GetLastError;
          case result of
            ERROR_ACCESS_DENIED: sInfo := 'ERROR_ACCESS_DENIED';
            ERROR_CIRCULAR_DEPENDENCY: sInfo := 'ERROR_CIRCULAR_DEPENDENCY';
            ERROR_DUPLICATE_SERVICE_NAME: sInfo := 'ERROR_DUPLICATE_SERVICE_NAME';
            ERROR_INVALID_HANDLE: sInfo := 'ERROR_INVALID_HANDLE';
            ERROR_INVALID_NAME: sInfo := 'ERROR_INVALID_NAME';
            ERROR_INVALID_PARAMETER: sInfo := 'ERROR_INVALID_PARAMETER';
            ERROR_INVALID_SERVICE_ACCOUNT: sInfo := 'ERROR_INVALID_SERVICE_ACCOUNT';
            ERROR_SERVICE_EXISTS: sInfo := 'ERROR_SERVICE_EXISTS';
          end;
        end
        else
        begin
          P := nil;
          StartService(hService, 0, p);   //启动服务   
          CloseServiceHandle(hService);
        end;
      finally
        CloseServiceHandle(hSCM);
      end;
    end;
    InstallService('服务名', '显示名', '服务路径');
      

  6.   

    请问怎么在程序中启动批处理文件?我用winexec(pchar('cmd.exe /c a.exe/install '),sw_show);
    一直不成功。。
      

  7.   


    用绝对路径试一试,如:c:\windows\system32\cmd.exe ,c:\a.exe或用ShellExecute,在uses ShellAPI;
      

  8.   


    winexec(pchar('c:\windows\system32\cmd.exe /c  c:\a.exe  /install'),sw_hide);依然不管事
      

  9.   

    winexec(pchar('c:\windows\system32\cmd.exe /c c:\a.exe /install'),sw_hide);管事了,哈哈。。刚才我试的时候少了空格,回上一贴时,加了空格,于是过了!
    谢谢楼上朋友!!