最近在标签打印程序中 需要开启WINDOWS服务
不多说 代码
private void StartService()
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
string a = "net start " + "\"Commander Service\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(a);
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
} |