473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

WMI Exception - System.Runtime.InteropServices.COMException

I have a Windows service written in C# that is configured to automatically
start. Sometimes - maybe 20% of the time - the service fails to start due to
an exception in WMI code. I haven't made my service dependent on WMI (or any
other service) because it appears that .net WMI calls automatically start the
WMI service if necessary. Below are the details. What causes this? How can I
make this code work 100% of the time? The code is trying to translate a
well-known group SID to its name like "Administrators". I was thinking about
wrapping my code in try catch and if it fails, waiting 5 seconds and trying
again, but this is guesswork. I also might make the service dependent on
winmgmt.

Here's the exception:

Service cannot be started.
System.Runtime.InteropServices.COMException (0x80010002)
Call was canceled by the message filter.
(Exception from HRESULT: 0x80010002 (RPC_E_CALL_CANCELED))
at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(O bject o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initial ize()
at System.Management.ManagementObjectSearcher.Get()
at
Magaram.TimeLimits.Server.AccountManager.GetGroupN ameFromSid(SecurityIdentifier sid)
at Magaram.TimeLimits.Server.AccountManager..ctor()
at
Magaram.TimeLimits.Server.TimeLimitService.CreateR ealService(SessionManager
sessionManager)
at
Magaram.TimeLimits.ServerHost.TimeLimitsWindowsSer vice.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

My code:

internal static string GetGroupNameFromSid(SecurityIdentifier sid) {
SelectQuery query = new SelectQuery("Win32_Group",
string.Format("Domain='{0}'", Environment.MachineName));
using (ManagementObjectSearcher searcher = new
ManagementObjectSearcher(query)) {
foreach (ManagementObject group in searcher.Get()) {
string sddl = group["SID"] as string;
if (sddl.ToLower().Trim() == sid.Value.ToLower().Trim()) {
string groupName = (string)(group["Name"]);
return group["Name"] as string;
}
}
}
throw new ArgumentOutOfRangeException("sid",
string.Format("Could not get the group name for sid: {0}", sid.Value));
}
Sep 22 '08 #1
0 3655

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jez123456 | last post by:
Hi, I have a c# program for compacting msaccess databases and I’m now setting up the exception handling. For 2 different conditions I get the following messages. ...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
4
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
8
by: Philip Colmer | last post by:
I'm rewriting some existing VBScript into VB.Net code. It was all going well until I hit the following error when testing the code: System.Runtime.InteropServices.COMException (0x80041003) at...
1
by: Philip Colmer | last post by:
I'm rewriting some existing VBScript into VB.Net code. It was all going well until I hit the following error when testing the code: System.Runtime.InteropServices.COMException (0x80041003) at...
5
by: cj | last post by:
When I run myMAPIMessage.Send(True) if the user cancels the resulting email it causes an exception. How do I trap this particular exception and say that's ok? try myMAPIMessage.Send(True)...
2
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
1
by: umeshatpromact | last post by:
Hello!, I got following exception when using COM component for EXCEL object in ASP .Net. I have added reference of "Microsoft.Office.Interop.Excel.dll" I deployed an application on local...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.