innosetup 6.1.2 停止服务的代码
时间: 2024-02-01 16:04:18 浏览: 28
innosetup 6.1.2 版本中停止服务的代码与之前的版本略有不同。具体的做法是:
1. 在[Code]段落中添加以下代码:
```
[Code]
function StopService(serviceName: String): Boolean;
var
serviceState: Cardinal;
serviceHandle: Integer;
begin
Result := False;
serviceHandle := OpenService(WinsvcManager, serviceName, SERVICE_STOP or SERVICE_QUERY_STATUS);
if serviceHandle <> 0 then
begin
try
if ControlService(serviceHandle, SERVICE_CONTROL_STOP, ServiceStatus) then
begin
Sleep(100);
while QueryServiceStatus(serviceHandle, ServiceStatus) do
begin
if ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING then
Sleep(1000)
else
Break;
end;
if ServiceStatus.dwCurrentState = SERVICE_STOPPED then
Result := True;
end;
finally
CloseServiceHandle(serviceHandle);
end;
end;
end;
```
其中,serviceName表示需要停止的服务名称,您需要将其替换为实际的服务名称。
2. 在需要停止服务的地方调用StopService函数即可,例如:
```
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
if IsServiceRunning('MyService') then
StopService('MyService');
end;
end;
```
其中,'MyService'表示需要停止的服务名称,您需要将其替换为实际的服务名称。
希望这个回答能够帮到您。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)