473,395 Members | 2,796 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,395 software developers and data experts.

WQLEventQuery:Second local connect:Access denied![II]

Hi All,

I've already asked another question [wmi newsgroup only], but this is
finally the same issue. I cannot execute two asynchron WMI queries on the
local machine, one after the other. The original question is based on
complicated code. So I reduced the "kernel" to a small C# sample [compilable
to exe], which shows the problem. The question is:

- Is this a problem with my code, as not freeing resources etc?
- Is this possibly a WMI issue?

In the original code, I tried to remove the querying class completely, but
even this does not help. Each second query fails.

Any help would really become very welcomed, each simple tip or hint!!!

Best regards,
Manfred Braun

(Private)
Lange Roetterstrasse 7
D68167 Mannheim
Germany

mailto:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)
Annotation:The executable has to be called with an computername as an
argument. The exe should work with each remote machine, but not with the
local one.

/*
Name: WMIAsyncQuerySampleReconnectSample5a.cs
*/
using System;
using System.Management;

class Sample_ManagementEventWatcher
{
public static int Main(string[] args)
{
if(args.Length != 0)
{
string comp = args[0];

MyHandler mh;
EventArrivedEventHandler eventArrivedEventHandler;
ManagementEventWatcher watcher;

mh = new MyHandler();
eventArrivedEventHandler = new EventArrivedEventHandler(mh.Arrived);
watcher = Sample_ManagementEventWatcher.getWatcher(comp);
watcher.EventArrived += eventArrivedEventHandler;

//Start watching for events:
watcher.Start();
Console.WriteLine("Watcher is running, press <enter> to stop...");
Console.ReadLine();
//Stop watching:
watcher.Stop();
watcher.EventArrived -= eventArrivedEventHandler;

mh = null;
watcher = null;
eventArrivedEventHandler = null;

Console.WriteLine("Watcher is stopped, press <enter> to re-start...");
Console.ReadLine();

mh = new MyHandler();
eventArrivedEventHandler = new EventArrivedEventHandler(mh.Arrived);
watcher = Sample_ManagementEventWatcher.getWatcher(comp);
watcher.EventArrived += eventArrivedEventHandler;

//Start watching for events:
try
{
watcher.Start(); //BOMBs here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Console.WriteLine("Watcher is running, press <enter> to stop...");
Console.ReadLine();
//Stop watching:
watcher.Stop();
watcher.EventArrived -= eventArrivedEventHandler;
}
catch(Exception e)
{
Console.WriteLine("Exception:{0}", e.ToString());
}
}
else
{
Console.WriteLine("Args!!! [P1=Computername]");
}
return 0;
}

public static ManagementEventWatcher getWatcher(string comp)
{
ConnectionOptions co;
ManagementPath mp;
ManagementScope ms;
WqlEventQuery EventQuery;
ManagementEventWatcher watcher;
string wql;

co = new ConnectionOptions();
co.Timeout = new TimeSpan(0, 0, 60);
co.EnablePrivileges = true;

mp = new ManagementPath();
mp.NamespacePath = @"root\cimv2";
mp.Server = comp;
ms = new ManagementScope(mp, co);

wql = "select * from __instancecreationevent where targetinstance isa
'Win32_NTLogEvent'";
EventQuery = new WqlEventQuery(wql);
watcher = new ManagementEventWatcher(ms, EventQuery);

co = null;
mp = null;
ms = null;
EventQuery = null;
wql = null;

return watcher;
}

public class MyHandler
{
public void Arrived(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject mbo =
(ManagementBaseObject)e.NewEvent["TargetInstance"];
Console.WriteLine("Event:{0}", mbo["message"]);
}

}//Inner class.
}//Class
Nov 15 '05 #1
0 2476

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

Similar topics

9
by: | last post by:
Hi All, I have allready tried to ask a similar question , but got no answer until now. In the meantime, I found, that I cannot understand some thread-settings for the Main() function . If I use...
6
by: Andrea | last post by:
I need to detect when another application is launched. I'd need to know also when a new folder is opened in explorer. I'm developing an application to speed up access to frequently used...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.