locked
Windows Service Access Denied when Configured in IIS RRS feed

  • Question

  • User-574293449 posted

    hi,

      I have a website applciation which have one page to start / stop my windows services. I used Impersonation for this. Credentials can be given in web.config and validate thorugh Impersonate class. The code for this class incldue the following methods

        public bool impersonateValidUser()
        {
            WindowsIdentity tempWindowsIdentity;
            IntPtr token = IntPtr.Zero;
            IntPtr tokenDuplicate = IntPtr.Zero;
    
            if (RevertToSelf())
            {
                if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
                    LOGON32_PROVIDER_DEFAULT, ref token) != 0)
                {
                    if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
                    {
                        tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
                        impersonationContext = tempWindowsIdentity.Impersonate();
                        if (impersonationContext != null)
                        {
                            CloseHandle(token);
                            CloseHandle(tokenDuplicate);
                            return true;
                        }
                    }
                }
            }
            if (token != IntPtr.Zero)
                CloseHandle(token);
            if (tokenDuplicate != IntPtr.Zero)
                CloseHandle(tokenDuplicate);
            return false;
        }
    
        public void undoImpersonation()
        {
            impersonationContext.Undo();
        }

    In the service start button i called impersonateValidUser() method. If it returns true i start the service using ServiceController class object

    When i run from Visual Studio I can start and stop my windows services thorugh the page.

    But when i call the page from IE (configured IIS 7) it returns the following error

    "Cannot open XXX service on computer '.'."

    where xxx is the windows service name

    Kindly guid me to solve this issue. Any permission in IIS level?

     

     

    Wednesday, August 21, 2013 6:39 AM

Answers

  • User-574293449 posted

    I solved. I enable ASPImpersonate in IIS and give access to the user for Service using subinacl

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 21, 2013 12:06 PM

All replies

  • User-574293449 posted

    I solved. I enable ASPImpersonate in IIS and give access to the user for Service using subinacl

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 21, 2013 12:06 PM
  • User-1058753816 posted

    I solved. I enable ASPImpersonate in IIS and give access to the user for Service using subinacl

    Would you mind sharing the references how to enable ASPImpersonate in IIS for us?

    I tried to solve the similar issue occred in my project but failed. It will be quite helpful for us if you shared the way how to enable the ASPImpersonate.

    Have a nice day.Smile

    Friday, August 23, 2013 3:37 AM
  • User-574293449 posted

    you have option in iis authnetication section

    Friday, August 23, 2013 9:50 PM