Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - WMI Exception - System.Runtime.InteropServices.COMException

Reply
 
Old 09-22-2008   #1 (permalink)
jmagaram


 
 

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.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at
Magaram.TimeLimits.Server.AccountManager.GetGroupNameFromSid(SecurityIdentifier sid)
at Magaram.TimeLimits.Server.AccountManager..ctor()
at
Magaram.TimeLimits.Server.TimeLimitService.CreateRealService(SessionManager
sessionManager)
at
Magaram.TimeLimits.ServerHost.TimeLimitsWindowsService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(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));
}

My System SpecsSystem Spec
Old 09-28-2009   #2 (permalink)
Hassan Tahir


 
 

Found any solution

Hi,

I am having the same kind of problem, while using ManagementEven****cher class in system.management namespace. I need to know that if find any solution/reason for the problem you are having.

Thanks

Hassan



jmagara wrote:

WMI Exception - System.Runtime.InteropServices.COMException
22-Sep-08

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.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at
Magaram.TimeLimits.Server.AccountManager.GetGroupNameFromSid(SecurityIdentifier sid)
at Magaram.TimeLimits.Server.AccountManager..ctor()
at
Magaram.TimeLimits.Server.TimeLimitService.CreateRealService(SessionManager
sessionManager)
at
Magaram.TimeLimits.ServerHost.TimeLimitsWindowsService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(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));
}

EggHeadCafe - Software Developer Portal of Choice
WPF DataGrid Custom Paging and Sorting
http://www.eggheadcafe.com/tutorials...tom-pagin.aspx
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Object cast exception at runtime .NET General
System Service Exception Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46