Open the References for the project in the Solution
Explorer and add a checkmark next to System.Management.
- Wayne
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I receive "Type 'managementeventwatcher' is not defined" error in compilation.
My code is as below:
Imports System.Runtime.InteropServices
Imports System
Imports System.management
'Imports System.ManagementEventWatcher
Namespace monitordrives
End Namespace
Module Program
Class program
Public Enum EventType
Inserted = 2
Removed = 3
End Enum
Sub Main()
Dim watcher As ManagementEventWatcher = New ManagementEventWatcher()
Dim query As WqlEventQuery = New WqlEventQuery()
AddHandler watcher.EventArrived, AddressOf watcher_EventArrived
watcher.Query = query
watcher.Start()
Console.ReadKey()
End Sub
Private Sub watcher_EventArrived(ByRef sender As Object, ByRef e As EventArrivedEventArgs)
Dim driveName As String = e.NewEvent.Properties("DriveName").Value.ToString()
Dim eventType As EventType = CType((Convert.ToInt16(e.NewEvent.Properties("EventType").Value)), EventType)
Dim eventName As String = [Enum].GetName(GetType(EventType), eventType)
Console.WriteLine("{0}: {1} {2}", DateTime.Now, driveName, eventName)
End Sub
'Sub Main()
' Console.WriteLine("Port Connected")
'End Sub
'Public Class socket
'Dim usbdevice As socket = New socket()
'Event usbarrival(ByVal iev As Integer)
' Sub usbdevice_usbarrival()
' AddHandler usbdevice.usbarrival, AddressOf Me.usbdevice_usbarrival
' End Sub
'End Class
End Class
End Module
This error is received five times for other parameters anywhere I used As 'Type'.
Please help me.
Thanks
Open the References for the project in the Solution
Explorer and add a checkmark next to System.Management.
You shouldn't have to copy anything. How did you
look for System.Management? Did you open the
References by right-clicking on that node in the
project tree in the Solution Explorer window?
Then choose "Add Reference" from the menu.
Scroll down the Framework list and you should find
System.Management.
If you can't find System.Management then perhaps the project is .NET Core (or regular .NET Framework) and if so add the reference via NuGet.
Link to NuGet package.
Hi ,thanks a part of my problem is resolved.Now I have event 'load' can not be found error and 'msgbox' is not declared error.this is the line concerns my first error:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
and the second error:
MsgBox(ex.Message)
Which libraries I have to install?
Please help me.
Thank you very much
No additional libraries are needed. You can try using MessageBox.Show instead and would recommend using Form Shown event rather than Form Load.