启动时运行 C# 程序时服务未启动异常

本文关键字:启动 异常 服务 运行 程序 | 更新日期: 2023-09-27 17:55:26

我有一个系统托盘应用程序,它已安装并开始从登录脚本运行。

该程序在启动时失败,因为它说服务未启动,但我不知道是哪一个。

我以为是RPC服务(name=RpcSs)。 这是我尝试但没有奏效的:

string ServiceName_Rpc = "RpcSs";
ServiceController controller = new ServiceController(ServiceName_Rpc);
controller.WaitForStatus(ServiceControllerStatus.Running);

服务器服务未启动。(HRESULT的例外:0x80070842)

at System.DirectoryServices.DirectoryEntry.RefreshCache() at System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() 在 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable 1 identityType, String identityValue, DateTime refDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) at System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) at System.DirectoryServices.AccountManagement.AuthZSet.get_CurrentAsPrincipal() at System.DirectoryServices.AccountManagement.FindResultEnumerator 1.get_Current() at System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable 1 source)

启动时运行 C# 程序时服务未启动异常

它指出错误消息中的哪个服务:

服务器服务未启动

服务器服务:

支持文件、打印和命名管道 为此通过网络共享 计算机。如果此服务已停止, 这些功能将不可用。 如果禁用此服务,则任何 明确依赖它的服务 将无法启动。

尝试更改代码以等待此服务,看看您是否有运气。虽然,我不确定你在做什么需要这项服务,所以不能保证它会起作用。