Access Denied while trying to stop a C# Windows Service

后端 未结 1 1928
北荒
北荒 2021-01-03 01:44

I have created a C# web service using visual studio to stop the windows service \'Simple Mail Transfer Protocol (SMTP)\' called SMTPSVC.

The following is the web met

相关标签:
1条回答
  • 2021-01-03 01:47

    The IUSER_machinename (IUSER for short, in the following) account is, for good reasons, a relatively limited account, with little more privilege than a guest account. It isn't allowed to start and stop Windows services, or even to interrogate them (to get their status etc).
    When run in the context of a stand-alone exe, the logic above is successful because the underlying account is [probably] you who is likely a member of the Administrators group, or a rather powerful account at any rate.

    The easy, but unrecommended way out of this situation, is to give the IUSER account more privileges. Just to try add this account to the Administrators group, bam!, it will work (but will also introduce some potentially dangerous security hole).
    A better approach is to make the explicit list of the particular Windows services that will be allowed to managed by way of IIS, and to set their individual service security descriptor to so that the IUSER account (or another account/group created for the occasion) be allowed to start and/or stop them as desired.
    The difficulty in implementing this approach is that, to my knowledge, there's no GUI or intuitive admin tool to inspect and alter the services' security descriptor: you need to use sd and "learn" the SDDL language. Here are a few pointers to do so

    • MSDN Best practices and guidance for writers of service discretionary access control lists
    • sc sdshow command
    • sc sdset command
    0 讨论(0)
提交回复
热议问题