1

I have vs2010 click once winform program that performs the setup for another program. This setup program makes sure that they sql server is installed, creates the database/logins/tables, enables mixed mode, restarts the sql server(2008 express) then adds the stored procedures using the login and preloads some tables to get started. Works fine for winXP. When i do the setup on a Windows 7, it fails when it tries to restart the server.

I'm guessing it's a win 7 UAC 'feature' that prevents it, when I manually restart the server I get a UAC alert. I'm currently using the 'stopService' and 'startService' functions from http://www.csharp-examples.net/restart-windows-service/

Is there another way to do this in code without me having to install the SSMS to manually restart in Windows 7?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dave k
  • 1,329
  • 4
  • 22
  • 44
  • The way you've linked is the right way to do it. Can you provide more details on how precisely it fails? Dollars to donuts, it's executing in the wrong security context. – Chris B. Behrens Sep 07 '11 at 21:16
  • To avoid installing SSMS use the Services MMC snapin: Start->Run->Services.msc Find the SQL Server services and right click and select 'Restart'. – Jeremy Sep 07 '11 at 21:24
  • I believe this will point you in the right direction. http://stackoverflow.com/questions/133379/elevating-process-privilege-programatically – ScottTx Sep 07 '11 at 21:25
  • Also have a look at Manifest files. You can embed one into your application that requests UAC privileges on app startup, that way you will be able to restart Windows Services without error. http://msdn.microsoft.com/en-us/library/bb756929.aspx – Jeremy Sep 07 '11 at 21:25

1 Answers1

1

Have you tried running a prepared .bat file that restarts the sql instance via: net stop mssqlserver net start mssqlserver

rapidfyre
  • 65
  • 9
  • Restarting the service seems to be the best way. Note: You can also use WIM to restart a service locally and remotely. – Jeremy Sep 07 '11 at 21:22
  • 1
    ^ WMI is what I should have typed. Windows Management Instrumentation. – Jeremy Sep 07 '11 at 21:28