好的,这是真正为我工作的东西,它已经在具有不同操作系统(Vista,XP,Win2k,Win2003服务器)的多台计算机上进行了测试。该代码已从此处获取,因此无论谁编写此代码都应归功于此。将dll或源文件添加到项目后,请确保添加ServiceTools命名空间,然后您可以访问一些非常方便的功能,例如...//Installs and starts the serviceServiceInstaller.InstallAndStart("MyServiceName", "MyServiceDisplayName", "C:\\PathToServiceFile.exe");//Removes the serviceServiceInstaller.Uninstall("MyServiceName");//Checks the status of the serviceServiceInstaller.GetServiceStatus("MyServiceName");//Starts the serviceServiceInstaller.StartService("MyServiceName");//Stops the serviceServiceInstaller.StopService("MyServiceName");//Check if service is installedServiceInstaller.ServiceIsInstalled("MyServiceName");