Questions tagged [managementeventwatcher]

`ManagementEventWatcher` class is from `System.Management` namespace. It can be used to subscribe to temporary WMI event notifications based on a specified event query.

ManagementEventWatcher class is from System.Management namespace. It can be used to subscribe to temporary WMI event notifications based on a specified event query.

37 questions
9
votes
1 answer

How does one use ManagementEventWatcher to keep track of suspend/resume?

I am trying to use ManagementEventWatcher in a service to keep track of when a computer goes in and out of sleep mode. I am new to .NET and C# so I am struggling quite a bit to come up with syntax to make this work. I have found a blog post that…
Tomek
  • 4,689
  • 15
  • 44
  • 52
8
votes
4 answers

Access to the path 'c:\$Recycle.Bin\S-1-5-18' is denied

I have this code to copy all files from source-directory, F:\, to destination-directory. public void Copy(string sourceDir, string targetDir) { //Exception occurs at this line. string[] files = System.IO.Directory.GetFiles(sourceDir, "*.jpg",…
Umair Ayub
  • 19,358
  • 14
  • 72
  • 146
7
votes
1 answer

what can you query using the ManagementEventWatcher class

have been playing with the ManagementEventWatcher class and am curious what system events and objects you can select * from .. Is there a published list somewhere?
Grant
  • 11,138
  • 32
  • 94
  • 140
6
votes
0 answers

Use WMI ManagementEventWatcher to listen for Bluetooth devices connected/disconnected

New to WMI and am kind of feeling around in the dark a bit, The following code detects connecting and disconnecting USB devices, but I also need to detect when a BT device is connected/disconnected (not just paired). ManagementEventWatcher watcher…
Wobbles
  • 3,033
  • 1
  • 25
  • 51
5
votes
1 answer

WMI query in C# does not work on NON-English Machine

I am creating an application that needs to track when a process starts, then raise an event when it's finished. I have code that works perfectly, and does exactly what I need on an English machine, but when I run the same application on a French…
SmithMart
  • 2,731
  • 18
  • 35
4
votes
1 answer

How do I get newly inserted USB drive letter in c#?

I wrote a c# program to find newly inserted USB drive and its drive letter. Now when I run this program I got the insertion event and couldn't get the drive letter. Can anyone suggest me an idea to do this? code static void Main(string[] args) { …
Hybrid Developer
  • 2,320
  • 1
  • 34
  • 55
4
votes
1 answer

System.Management.ManagementException "Access Denied" with Win32_ProcessStartTrace

I have a piece of code to handle scenarios where specific processes are started or stopped and in order to achieve this I am using ManagementEventWatcher. string queryStart = "SELECT * FROM Win32_ProcessStartTrace" + "…
Tsst
  • 101
  • 2
  • 10
4
votes
3 answers

Exception while ManagementEventWatcher(WMI) to notify events from remote machine

I am trying to get notification from a remote machine 's event viewer using WMI and C#. I am able to connect the system and also get event log by using ManagementObjectSearcher. But when I tried to use ManagementEventWatcher.Start method I am…
Devendra
  • 41
  • 1
  • 3
4
votes
2 answers

Not found exception When start the ManagementEventWatcher

Not Found Exception some times while starting the MaagementEventWatcher My code sample is given below : try { string scopePath = @"\\.\root\default"; ManagementScope managementScope = new ManagementScope(scopePath); …
Vikram Bose
  • 3,197
  • 2
  • 16
  • 33
3
votes
0 answers

Multiple callback came while Usb device connected

var watcher = new ManagementEventWatcher(); var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 or EventType = 3"); watcher.EventArrived += new…
3
votes
1 answer

How do I detect insertion of USB devices category wise in C# winform?

USB thumb drives USB harddisks USB DVD writer USB Bluetooth devices USB headsets usb mouse USB keyboard USB webcams / cameras Just want to detect any sort of usb device using event handler... Would appreciate any help... WqlEventQuery q_creation =…
Ajith kp
  • 81
  • 4
2
votes
2 answers

The type or namespace name 'ManagementEventWatcher' not found

Why do I get The type or namespace name 'ManagementEventWatcher' not found in the following code: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using…
red eyes dev
  • 398
  • 3
  • 11
2
votes
1 answer

Detecting USB drive insertion and removal using windows service and Vb.Net

I want in my application to detect if a USB Drive is plugged in or plugged out. I have googled a lot about it and actually found a lot answers but none worked exactly how I wanted it to be. I found one that works perfectly and give message when a…
2
votes
1 answer

ManagementEventWatcher - InvalidComObjectException when application exists

I have build a .net library that uses the ManagementEventWatcher class. My library is disposable, so normally I would wrap it in a using statement and the ManagementEventWatcher class would get disposed by my library. My issue is that my library…
Jeremy
  • 44,950
  • 68
  • 206
  • 332
1
vote
1 answer

vb.net - managementeventwatcher not capturing a second instance of any process

I've got an application which is watching over executed processes on a device using a managementeventwatcher, like so... Dim wmiq As String = "SELECT TargetInstance FROM __InstanceCreationEvent WITHIN .025 WHERE TargetInstance ISA…
John
  • 755
  • 1
  • 18
  • 46
1
2 3