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

问题描述:

我有一个系统托盘应用程序,它已安装并开始从登录脚本运行。在启动时运行C#程序时服务未启动异常

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

我认为这是RPC服务(名称= RpcSs)。以下是我试过,但没有奏效:

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

服务器服务未启动。 (从HRESULT异常:0x80070842)

在System.DirectoryServices.DirectoryEntry.RefreshCache() 在System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit() 在System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() 在系统.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() 在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext上下文中,类型principalType,可空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() 在System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable 1源)

它说,该服务的错误消息:

服务器服务未启动

服务器服务:

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

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

+2

感谢您指出。我没有意识到“服务器”是一项服务。我完全误解了这个信息。 – skeletank 2011-05-06 20:33:16