首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServiceController权限Windows 2016

ServiceController权限Windows 2016
EN

Stack Overflow用户
提问于 2018-10-18 22:12:17
回答 1查看 327关注 0票数 0

我们有一个遗留应用程序,它最近部署在一个Windows 2016实例上。我们遇到了访问被拒绝的错误,当它托管在Windows 2012框中时,我们没有看到这些错误。

服务帐户具有启动/停止服务的权限。我们关心的一件事是,它实际上是一个监视服务。这意味着,它正在检查运行在不同服务下的主应用程序是否正确地处理来自队列的数据。如果出现问题,此服务将重新启动。我想知道在Windows 2016中是否有任何改变改变了访问配置文件。多年来,代码没有任何变化。

如有任何建议或想法,将不胜感激。

误差

代码语言:javascript
复制
System.ComponentModel.Win32Exception: Access is denied
--- End of inner exception stack trace ---
   at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess)
   at System.ServiceProcess.ServiceController.Start(String[] args)
   at System.ServiceProcess.ServiceController.Start()
   at DacMonitor.Monitor.StartService(String serviceName, Int32 timeoutMilliseconds)

代码:

代码语言:javascript
复制
   public static void RestartService(string serviceName, int timeoutMilliseconds)
    {
        Log.Info(string.Format("Going to attempt to restart service: {0}", serviceName));
        try
        {
            ServiceController service = new ServiceController(serviceName);
            int millisec1 = Environment.TickCount;
            TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

            Log.Info(string.Format("Stopping service: {0}", serviceName));
            if (service.Status != ServiceControllerStatus.Stopped &&
                service.Status != ServiceControllerStatus.StopPending)
            {
                service.Stop();                    
            }

            service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

            // count the rest of the timeout
            int millisec2 = Environment.TickCount;
            timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - (millisec2 - millisec1));

            Log.Info(string.Format("Starting service: {0}", serviceName));
            service.Start();
            service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }
        catch(Exception ex)
        {
            Log.Error(string.Format("Error trying to restart the service: {0}", serviceName), ex);
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2018-10-31 13:00:36

我们发现我们最终需要给用户帐户管理员凭据。可能有一些额外的权限,我们可以给予帐户,试图让它工作,但至少在目前决定,只是给予它这些权利。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52883315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档