C# 啟動 SQL Server 服務


 1  //首先要添加 System.ServiceProcess.dll  引用
 2             ServiceController sc = new ServiceController("MSSQLSERVER");
 3 
 4             //判斷服務是否已經關閉
 5             if (sc.Status == ServiceControllerStatus.Stopped)
 6             {
 7                 sc.Start();
 8                 MessageBox.Show("SQL數據庫服務啟動成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
 9             }
10 
11             //判斷服務是否已經開啟
12             if (sc.Status != ServiceControllerStatus.Stopped)
13             {
14                 sc.Stop();
15                 MessageBox.Show("SQL數據庫服務成功關閉!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
16             }
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM