I am working on utility which is used to install service application. I want to add one more feature as install service with custom service name and display name.
So far I tried with using CreateProcess
with command string as
ExePath sysNameId:XXX -install
.
using this I am able install service but the name is not able to change.
Can anyone give me some leads on the same?
Below Is the code I am using to install service.
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;
Calling for the function ExecuteServiceCommand is
ServiceEXEname.exe sysNameId:XXXX -install
Thanks in Advance.