procedure TForm1.Button_StartApacheClick(Sender: TObject);
begin
a := edit_ApachePath.Text + '\bin\httpd.exe';
b := edit_ApachePath.Text + '\bin';
//ShellExecute(Self.handle,'open', PWideChar(a),'','',SW_SHOWNORMAL);
FillChar(ApacheProcessInfo,sizeof(ApacheProcessInfo),0);
FillChar(ApacheStartupInfo,Sizeof(ApacheStartupInfo),0);
ApacheStartupInfo.cb:=Sizeof(ApacheStartupInfo);
ApacheStartupInfo.dwFlags:=STARTF_USESHOWWINDOW;
ApacheStartupInfo.wShowWindow:=SW_HIDE;
a := StringReplace(a, '\', '\\', [rfReplaceAll]);
b := StringReplace(b, '\', '\\', [rfReplaceAll]);//转换自动获取的路径中的 \ 为 \\
//将EXE所在工作目录转到CreateProcess中,没有调用成功的主要原因就在于此
If CreateProcess(PWideChar(a),nil,nil,nil,False,0,
nil,PWideChar(b),ApacheStartupInfo,ApacheProcessInfo) then
begin
memo1.Lines.Add('[' + FormatdateTime('hh:nn:ss', Now)+ '] Apache服务启动成功');
//memo1.Lines.Add(a);
end
else
begin
memo1.Lines.Add('[' + FormatdateTime('hh:nn:ss', Now)+ '] Apache服务启动失败,请检查相关配置');
end;
end;
var
ApacheStartupInfo:TStartupInfo;
ApacheProcessInfo:TProcessInformation;
begin
a := edit_ApachePath.Text + '\bin\httpd.exe';
b := edit_ApachePath.Text + '\bin';
//ShellExecute(Self.handle,'open', PWideChar(a),'','',SW_SHOWNORMAL);
FillChar(ApacheProcessInfo,sizeof(ApacheProcessInfo),0);
FillChar(ApacheStartupInfo,Sizeof(ApacheStartupInfo),0);
ApacheStartupInfo.cb:=Sizeof(ApacheStartupInfo);
ApacheStartupInfo.dwFlags:=STARTF_USESHOWWINDOW;
ApacheStartupInfo.wShowWindow:=SW_HIDE;
a := StringReplace(a, '\', '\\', [rfReplaceAll]);
b := StringReplace(b, '\', '\\', [rfReplaceAll]);//转换自动获取的路径中的 \ 为 \\
//将EXE所在工作目录转到CreateProcess中,没有调用成功的主要原因就在于此
If CreateProcess(PWideChar(a),nil,nil,nil,False,0,
nil,PWideChar(b),ApacheStartupInfo,ApacheProcessInfo) then
begin
memo1.Lines.Add('[' + FormatdateTime('hh:nn:ss', Now)+ '] Apache服务启动成功');
//memo1.Lines.Add(a);
end
else
begin
memo1.Lines.Add('[' + FormatdateTime('hh:nn:ss', Now)+ '] Apache服务启动失败,请检查相关配置');
end;
end;