1

I am trying to install an instance to SQL using the following code:

Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"D:\Softwares\SQL Server 2014\SQLEXPRADV_x64_ENU\SETUP",
@"/q /ACTION=Install /IAcceptSQLServerLicenseTerms=True /FEATURES=SQL /INSTANCENAME=PearlTrial /SQLSVCSTARTUPTYPE=Automatic /SQLSVCACCOUNT=""NT AUTHORITY\NETWORK SERVICE"" /SQLSYSADMINACCOUNTS=""BUILTIN\Administrators"" /AGTSVCACCOUNT=""NT AUTHORITY\Network Service"" /ADDCURRENTUSERASSQLADMIN=true /SECURITYMODE=SQL /SAPWD=""Password@123""");
p.StartInfo.UseShellExecute = true;
p.StartInfo.Verb = "runas";
p.Start();
p.WaitForExit();
p.Close();

Now the setup runs successfully but an error occured because the system needs to be restarted. Now I want to prompt the user if reboot is required and for that matter I need to read the output from the Process window. And for that I can do as:

p.StartInfo.RedirectStandardOutput = true;
using (StreamReader sr = p.StandardOutput)
{
    if (sr.BaseStream.CanRead)
    { var d = sr.ReadToEnd(); }
}

But it won't work because when UseShellExecute is true it does not create the process and hence the output can't be read, and if i do the following

p.StartInfo.UseShellExecute = false;

I got the error:

The requested operation requires elevation

How can I get the response from the process or How can I check if system reboot is needed?

I know there is a way to clear it in the registry

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager

and clear the PendingFileRenameOperations but I don't want to play with the registry. Is there any other cleaner way to do this?

Awais Mahmood
  • 1,308
  • 4
  • 21
  • 51

0 Answers0