我的 Windows 服务在启动时尝试通过其 UNC 路径访问本地共享。
它具有完整的权限并且路径存在,我可以说,因为在启动后很长时间启动我的服务时,一切正常。
但是,在启动时我遇到了错误
System.UnauthorizedAccessException: Access to the path '\\MyPc\Share' is denied.
我添加了一个重试机制,如果我不受限制地重试,它就可以工作,但这是一个糟糕的设计,可能会导致掩盖实际错误。
我的服务在安装时配置为依赖LanmanServer
( svchost.exe
),但我不确定这是否是负责在启动时设置网络共享的服务。找不到关于哪个服务或其他组件的文档。也可能是我错误配置了依赖项。从我的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>