安装前更改服务名称

时间:2019-02-19 12:07:43

标签: delphi service createprocess

我正在使用用于安装服务应用程序的实用程序。 我想使用自定义服务名称和显示名称来添加一项功能作为安装服务。

到目前为止,我尝试将CreateProcess与命令字符串一起使用  ExePath sysNameId:XXX -install。 使用此功能,我可以安装服务,但名称无法更改。

有人可以给我一些线索吗?

下面是我用来安装服务的代码。

    function ExecuteServiceCommand(pStrCommand: string; var Output, ErrorList: TStringList): Boolean;
var
  startUpInfo : TStartupInfo;
  processInfo : TProcessInformation;
  SecurityAttr : TSecurityAttributes;
  hPipeErrorsRead    : THandle;
  hPipeErrorsWrite   : THandle;
  hPipeOutputRead    : THandle;
  hPipeOutputWrite   : THandle;
  CreationFlags     : DWORD;
begin
  //initializing ProcessInfo
  FillChar(ProcessInfo, SizeOf(TProcessInformation), 0);

  //Initializing SecurityAttr
  FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);
  SecurityAttr.nLength              := SizeOf(TSecurityAttributes);
  SecurityAttr.bInheritHandle       := True;
  SecurityAttr.lpSecurityDescriptor := nil;

  //Create Piping handles
  CreatePipe(hPipeOutputRead, hPipeOutputWrite, @SecurityAttr, 0);
  CreatePipe(hPipeErrorsRead, hPipeErrorsWrite, @SecurityAttr, 0);

  //initialing StartupInfo
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  StartupInfo.cb          := SizeOf(TStartupInfo);
  StartupInfo.hStdInput   := 0;
  StartupInfo.hStdOutput  := hPipeOutputWrite;
  StartupInfo.hStdError   := hPipeErrorsWrite;
  StartupInfo.wShowWindow := SW_HIDE;
  StartupInfo.dwFlags     := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;

  // define flags
  CreationFlags := CREATE_DEFAULT_ERROR_MODE or
                   CREATE_NEW_CONSOLE or
                   NORMAL_PRIORITY_CLASS;

  // execute the process and get output
  if CreateProcess(nil,
                PChar(pStrCommand),
                nil,
                nil,
                true,
                CreationFlags,
                nil,
                nil,
                startUpInfo,
                processInfo
                ) then
   begin
     Result := true;
     // close write handles
     CloseHandle(hPipeErrorsWrite);
     CloseHandle(hPipeOutputWrite);

     // do something to read console output
     CloseHandle(hPipeErrorsRead);
     CloseHandle(hPipeOutputRead);
   end
  else
   begin
        //DoSomething
   end;

  Result := true;

end;

对函数Exec​​uteServiceCommand的调用是

ServiceEXEname.exe sysNameId:XXXX -install

谢谢。

0 个答案:

没有答案