用 C# 启动服务 [英] Start Service with C #

查看:46
本文介绍了用 C# 启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C# 启动服务,但出现以下错误:

ServiceController service = new ServiceController(sServiceName);service.MachineName = localComputerName;服务.开始();service.WaitForStatus(ServiceControllerStatus.Running);

<块引用>

System.InvalidOperationException:无法在计算机上打开服务System.ComponentModel.Win32Exception:访问被拒绝System.ServiceProcess.ServiceController.GetServiceHandle(Int32requiredAccess) 在 System.ServiceProcess.ServiceController.Stop()

解决方案

查找您的权限.请问您需要从管理员帐户运行您的应用程序(或 Visual Studio).

I'm trying to start a service with C # but throws me the following error:

ServiceController service = new ServiceController(sServiceName);
service.MachineName = localComputerName;
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);

System.InvalidOperationException: Cannot open service on computer System.ComponentModel.Win32Exception: Access is denied at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) at System.ServiceProcess.ServiceController.Stop()

解决方案

Look for your permissions. May me you need to run your app (or Visual Studio) from Administrator account.

这篇关于用 C# 启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆