Inno安装程序重新启动SQL Server Windows服务不起作用

时间:2018-10-24 08:59:54

标签: sql-server-2012 inno-setup pascal

我正在尝试使用SQL Server 2012安装inno setup。安装部分工作正常。我正在使用自定义端口来安装SQL Server,因此在安装后使用Windows Registry来更改RegWriteStringValue中的端口号,并尝试重新启动SQL Server服务以实现更改。

但是由于某种原因,我重新启动服务的逻辑无法通过我的代码工作。我使用以下过程来实现相同的目的。

procedure RestartService;
var

    CommandLine: String;
    MyResultCode: Integer;
begin       
        CommandLine := 'cmd /c NET STOP MSSQLSERVER /y < "C:\test\yes.txt" & NET START SQLSERVERAGENT > C:\test\Output.txt';    
        Log('Command line is.. ' + CommandLine);
        Exec('cmd.exe', CommandLine, '', SW_HIDE, ewWaitUntilTerminated, MyResultCode);
        Sleep(20000);
end;

文件yes.txt包含字符 Y 和新行,因为重新启动服务需要提示重新启动从属服务。

当我打开命令提示符并直接在命令行中运行命令时,它工作得很好,并给出了以下输出。

The following services are dependent on the SQL Server (MSSQLSERVER) service.
Stopping the SQL Server (MSSQLSERVER) service will also stop these services.

   SQL Server Agent (MSSQLSERVER)

The SQL Server Agent (MSSQLSERVER) service is stopping.
The SQL Server Agent (MSSQLSERVER) service was stopped successfully.

The SQL Server (MSSQLSERVER) service is stopping.
The SQL Server (MSSQLSERVER) service was stopped successfully.

但是在程序中,它似乎不起作用,并且将MyResultCode返回为1,并且在运行命令后写入输出的文件Output.txt为空。我想念什么?

预先感谢, 迪杰。

0 个答案:

没有答案