1

My Windows Service is trying to access a local share via its UNC path on its startup.

It has full permissions and path exists, I can tell that since when starting my service long after boot, everything works.

However, on boot time I'm getting errors

System.UnauthorizedAccessException: Access to the path '\\MyPc\Share' is denied.

I've added a retry mechanism, and it works if I retry without limitations, but that's bad design and could lead to covering up actual errors.

My service is configured to depend on LanmanServer (svchost.exe) when installed, but I'm not sure if that is the service that is responsible for setting up the network share on boot. Couldn't find documentation as to which service or other component is. Could also be that I misconfigured the dependency. From my wixproj:

<ServiceInstall Id="MyServiceId"
                Name="MyService"
                DisplayName="My Service"
                Description="The service which is mine"
                Start="auto"
                Type="ownProcess"
                ErrorControl="ignore"
                Vital="no" >
                <util:ServiceConfig FirstFailureActionType="restart" 
                            SecondFailureActionType="restart" 
                            ThirdFailureActionType="restart"
                            RestartServiceDelayInSeconds="60"
                            ResetPeriodInDays="49710"/>
  <ServiceDependency Id="LanmanServer"/> <!-- svchost.exe (netsvcs) -->
</ServiceInstall>
PhilDW
  • 20,260
  • 1
  • 18
  • 28
Mugen
  • 8,301
  • 10
  • 62
  • 140
  • 1
    Have you checked the timing vs a logon? I'm not absolutely sure, but most mapped drives are not connected until the owning user logs on. – PhilDW Jan 29 '18 at 18:30
  • @PhilDW How can I test this programmatically from my service code? (`C#`) – Mugen Jan 30 '18 at 07:34
  • 1
    I believe you override ServiceBase.OnSessionChange, and that callback will give you a session change description, one of the reasons in there is a logon. – PhilDW Jan 30 '18 at 18:37
  • @PhilDW indeed it should support logon: https://msdn.microsoft.com/en-us/library/system.serviceprocess.sessionchangereason%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 I'll try it, thanks – Mugen Jan 31 '18 at 06:36
  • let us know if that solves the problem, I'll post it as an answer. – PhilDW Jan 31 '18 at 18:05

0 Answers0