可以了, 开始:: net start "IIS Admin"--------启动IIS Admin服务 net start "SQL Server (MSSQLSERVER)"----------启动MSSQLSERVER服务 start "nu" "D:\Students\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe"-----打开SQL Server 2005程序结束:: @echo off taskkill /im SqlWb.exe /f-----关闭进程 net stop "SQL Server (MSSQLSERVER)" net stop "IIS Admin" exit
------------------
net start MSSQLSERVER停止
------------------
net stop MSSQLSERVER
我要开的服务是SQL Server (SQLEXPRESS).
一个StartSQL.bat 内容如下:
echo Start SQL
echo ------------------
net start MSSQLSERVER 另一个StopSQL.bat 内容如下:
echo Stop SQL
echo ------------------
net stop MSSQLSERVER
开始::
net start "IIS Admin"--------启动IIS Admin服务
net start "SQL Server (MSSQLSERVER)"----------启动MSSQLSERVER服务
start "nu" "D:\Students\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe"-----打开SQL Server 2005程序结束::
@echo off
taskkill /im SqlWb.exe /f-----关闭进程
net stop "SQL Server (MSSQLSERVER)"
net stop "IIS Admin"
exit
{
public Form1()
{
InitializeComponent();
if (sql.CanStop)
{
this.Text += " (Running)";
label1.Text = "确实要停止SQL Server及IIS服务吗?";
}
else
{
this.Text += " (Stopped)";
label1.Text = "确实要开启SQL Server及IIS服务吗?";
}
}
ServiceController sql = new ServiceController("SQL Server (SQLExpress)"); private void button1_Click(object sender, EventArgs e)
{
if (sql.CanStop)
{
sql.Stop();
System.Diagnostics.Process.Start("net","stop iisadmin /y");
}
else
{
sql.Start();
System.Diagnostics.Process.Start("net","start iisadmin");
} sql.Close();
button2_Click(null,null);
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
设计代码:
#region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(172, 101);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 0;
this.button1.Text = "确定(&O)";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(69, 101);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 0;
this.button2.Text = "取消(&C)";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("新宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(28, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AcceptButton = this.button1;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(292, 158);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SQL Server";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;