我是否需要启用交互式桌面才能使其正常工作以及启动EXE或cmd窗口的正确代码是什么?即使我启用它与桌面交互,我仍然无法启动该服务.
我将使用聊天引擎,因此它更容易作为Windows服务进行管理.
我的代码有什么问题?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading;
namespace MyNewService
{
class Program : ServiceBase
{
static void Main(string[] args)
{
}
public Program()
{
this.ServiceName = "Chatter";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
//TODO: place your start code here
ThreadStart starter = new ThreadStart(bw_DoWork);
Thread t = new Thread(starter);
t.Start();
}
private void bw_DoWork()
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Windows\system32\cmd.exe");
p.Start();
p.WaitForExit(); …Run Code Online (Sandbox Code Playgroud)