我正在尝试使用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
为空。我想念什么?
预先感谢, 迪杰。