开发者

TargetInstance ISA 'Win32_SerialPort'"

开发者 https://www.devze.com 2023-03-29 11:00 出处:网络
C#, WPF, Windows 7, PC, Visaul Studio 2010 I try to trap when the user attach a COM port to the PC by doing this

C#, WPF, Windows 7, PC, Visaul Studio 2010

I try to trap when the user attach a COM port to the PC by doing this

            myCOMAddEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_SerialPort'");
            myCOMAddEventQue.WithinInterval = TimeSpan.FromSeconds(1);
            myCOMAddWatcher = new ManagementEventWatcher(myCOMAddEventQue);
            myCOMAddWatcher.EventArrived += new EventArrivedEventHandler(COMAddEvent);
            myCOMAddWatcher.Start();

But this generates the error "ObjectDisposedException was unhandled" ??

I am able to trap USB memorysticks by

            myDiscA开发者_如何转开发ddlEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_LogicalDisk' and (TargetInstance.DriveType = 2 or TargetInstance.DriveType = 4)");

Why are Windows generating the error for the COM port?

Regards Stefan

0

精彩评论

暂无评论...
验证码 换一张
取 消