1

I'm installing SQL Server like the code below

Process.Start("Setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="<DomainName\UserName>" /SQLSVCPASSWORD="<StrongPassword>" /SQLSYSADMINACCOUNTS="<DomainName\UserName>" /AGTSVCACCOUNT="NT AUTHORITY\Network Service" /IACCEPTSQLSERVERLICENSETERMS");

When it fails to pass the pre-requisite check, the installer just disappears right away without showing the error message to the user.

I can check the reason why it failed by looking at program files folder for SQL Server but the person who is installing the software will not know where to look.

So I would like to let the user know what the error was. How can I achieve this?

Another problem I'm facing is that because this is running as a process, the program does not wait till the SQL Server installation to finish. Is there a way to run a process and wait for it to finish?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
fwan
  • 183
  • 2
  • 3
  • 14
  • read from the stderr & stdout streams: see [here](http://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net) how to do that – Alex Apr 26 '15 at 22:54
  • 1
    The code you posted is not valid code. the `"` don't match up. It is hard to tell if you are doing anything wrong if you don't show us the actual code causing the problem. – Scott Chamberlain Apr 26 '15 at 23:01
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 26 '15 at 23:03
  • 1
    I imagine that sending parameter `/q` might have something to do with it. You ask for a quiet setup, so that's what you get... – spender Apr 26 '15 at 23:24
  • The code posted is for a demonstration purpose that I found from another post. So I didn't check to see if it runs but I was trying to illustrate the problem as I am actually doing the same way as the code I posted – fwan Apr 27 '15 at 00:07
  • Alex's link is the answer to my question. Should I just delete my post as it's more like a duplicate question? – fwan Apr 27 '15 at 00:08

2 Answers2

1

So I would like to let the user know what the error was. How can I achieve this?

By reading from the stderr and stdout streams, assuming they will be used by Setup.exe to output an error message.

Another problem I'm facing is that because this is running as a process, the program does not wait till the SQL Server installation to finish. Is there a way to run a process and wait for it to finish?

You can wait for the process to exit, like this:

var process = Process.Start( .... );

// wait.
process.WaitForExit();

More information on both of these topics can be found here: How to spawn a process and capture its STDOUT in .NET? and here Process.start: how to get the output?

Community
  • 1
  • 1
Alex
  • 13,024
  • 33
  • 62
  • [link](http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output) was also helpful – fwan Apr 27 '15 at 00:18
  • @fwan good to know that setup does write to stderr; it was not obvious that it would. I will add that link to the answer. – Alex Apr 27 '15 at 00:20
1

The /q flag is for a silent install, so it does not display any information back to the user. Try without a /q flag.

DWright
  • 9,258
  • 4
  • 36
  • 53
  • /q flag is used for a silent install and if an error occurs, it displays the error message. It just disappears right away. So I think /q flag or any flag is not a problem – fwan Apr 27 '15 at 00:03
  • Ok, but does the error message stick around without the q flag? – DWright Apr 27 '15 at 00:03