473,386 Members | 1,819 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,386 software developers and data experts.

USB Pen Drive Detection - Retrieving

To anyone who is smarter than I am when it comes to WMI:

Here is what I am trying to do:

1) Detect a USB pen drive when it is inserted
2) Retrieve the drive letter of the pen drive
3) Check for a specific folder on the pen drive

I keep receiving an error message that reads:
An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll

The detection of the USB drive is working correctly, and it calls a
method called Arrival(). Within that method I call a CheckDrive()
method that is supposed to loop through all of the logical disks and
find a removable drive that contains a specific folder. I have also
gotten a System.ExecutionEngineException when the application gets to
the following line of code:

Dim moc As ManagementObjectCollection = disks.GetInstances()

I have also received a "Catastrophic Failure" message when this
same code is used in another conceptual application I wrote.

Is there a better way to do this, maybe I am going about it the wrong
way. Any help would be greatly appreciated.

Here is my code, I am using the DotNetFramework 1.1:

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Text
Imports System.management
Imports System.IO
Public Class DetectorForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
RegisterHidNotification()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DetectorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 333)
Me.Name = "DetectorForm"
Me.Text = "DetectorForm"

End Sub

#End Region
Private Sub Arrival()
MsgBox("Arrival")
CheckDrive()
End Sub

Private Sub Removal()
MsgBox("Removal")
End Sub
Public Sub CheckDrive()
Try
Dim disks As New ManagementClass("Win32_LogicalDisk")
Dim moc As ManagementObjectCollection =
disks.GetInstances()
Dim mo As ManagementObject
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty As PropertyData
Dim removableDisk As ManagementObject

'For each LogicalDisk on the Computer
For Each mo In moc
'Retrieve the disk's properties
DiskProperties = mo.Properties
'Iterate through the disk's properties
For Each DiskProperty In DiskProperties
'Check whether the particular property is defined
for this drive
If Not IsNothing(DiskProperty.Value) Then
'Check if the drive is removable DriveType=2 -
Removable
If DiskProperty.Name.ToString = "DriveType" _
And DiskProperty.Value.ToString = "2" Then
'Check if this Removable disk is a Zoom
Drive
Dim drvLetter As String
drvLetter =
mo.Properties("DeviceId").Value.ToString()
'Check if a directory exists
If Directory.Exists(drvLetter &
"chadc3322") Then
MsgBox("chadc3322 Exists")
Exit For
End If
End If
End If
Next
Next mo

disks.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub RegisterHidNotification()
Dim dbi As DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE = New
DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
Dim gd As Guid
' MsgBox(Marshal.SizeOf(gd))
' MsgBox(Marshal.SizeOf(New
Win32.DEV_BROADCAST_DEVICEINTERFACE))
dbi.dbcc_size = size
dbi.dbcc_devicetype = DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE
dbi.dbcc_reserved = 0
dbi.dbcc_classguid = DeviceDetector.GUID_IO_MEDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = DeviceDetector.RegisterDeviceNotification(Handle, Buffer,
DeviceDetector.DEVICE_NOTIFY_WINDOW_HANDLE)
Marshal.PtrToStructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToInt32 Then
'MessageBox.Show(DeviceDetector.GetLastError().ToS tring())
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = DeviceDetector.WM_DEVICECHANGE Then
OnDeviceChange(m)
End If
MyBase.WndProc(m)
End Sub
Private Sub OnDeviceChange(ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToInt32()
If wParam = DeviceDetector.DBT_DEVICEARRIVAL Then

Dim o As New DeviceDetector.DEV_BROADCAST_HDR
Dim b As New DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE1
Dim gd As Guid
Marshal.PtrToStructure(msg.LParam, o)
If (o.dbcc_devicetype =
DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE) Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(strsize)
Marshal.PtrToStructure(msg.LParam, b)
Dim str As New String(b.dbcc_name, 0, strsize)
'***********************************************
' Device Arrival
'***********************************************
Arrival()
End If
ElseIf wParam = DeviceDetector.DBT_DEVICEREMOVECOMPLETE Then
'***********************************************
' Device Removal
'***********************************************
Removal()
End If
End Sub
Private Class DeviceDetector
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIVAL = &H8000
Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_WINDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_SERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVICEINTERFACE = 5
Public Shared GUID_IO_MEDIA_ARRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
_
Public Class DEV_BROADCAST_DEVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(UnmanagedType.ByValArray,
ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Public dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> _
Public dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_HDR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class
<DllImport("user32.DLL", SetLastError:=True)> _
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal
NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
<DllImport("kernel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class
End Class

Mar 3 '06 #1
8 8469
Hi,

Why dont you let the wmi tell you when the usb drive is inserted?

http://www.vb-tips.com/default.aspx?...a-07a4ef9d9504

Ken
-------------------
"Chad" <ch********@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
To anyone who is smarter than I am when it comes to WMI:

Here is what I am trying to do:

1) Detect a USB pen drive when it is inserted
2) Retrieve the drive letter of the pen drive
3) Check for a specific folder on the pen drive

I keep receiving an error message that reads:
An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll

The detection of the USB drive is working correctly, and it calls a
method called Arrival(). Within that method I call a CheckDrive()
method that is supposed to loop through all of the logical disks and
find a removable drive that contains a specific folder. I have also
gotten a System.ExecutionEngineException when the application gets to
the following line of code:

Dim moc As ManagementObjectCollection = disks.GetInstances()

I have also received a "Catastrophic Failure" message when this
same code is used in another conceptual application I wrote.

Is there a better way to do this, maybe I am going about it the wrong
way. Any help would be greatly appreciated.

Here is my code, I am using the DotNetFramework 1.1:

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Text
Imports System.management
Imports System.IO
Public Class DetectorForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
RegisterHidNotification()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DetectorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 333)
Me.Name = "DetectorForm"
Me.Text = "DetectorForm"

End Sub

#End Region
Private Sub Arrival()
MsgBox("Arrival")
CheckDrive()
End Sub

Private Sub Removal()
MsgBox("Removal")
End Sub
Public Sub CheckDrive()
Try
Dim disks As New ManagementClass("Win32_LogicalDisk")
Dim moc As ManagementObjectCollection =
disks.GetInstances()
Dim mo As ManagementObject
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty As PropertyData
Dim removableDisk As ManagementObject

'For each LogicalDisk on the Computer
For Each mo In moc
'Retrieve the disk's properties
DiskProperties = mo.Properties
'Iterate through the disk's properties
For Each DiskProperty In DiskProperties
'Check whether the particular property is defined
for this drive
If Not IsNothing(DiskProperty.Value) Then
'Check if the drive is removable DriveType=2 -
Removable
If DiskProperty.Name.ToString = "DriveType" _
And DiskProperty.Value.ToString = "2" Then
'Check if this Removable disk is a Zoom
Drive
Dim drvLetter As String
drvLetter =
mo.Properties("DeviceId").Value.ToString()
'Check if a directory exists
If Directory.Exists(drvLetter &
"chadc3322") Then
MsgBox("chadc3322 Exists")
Exit For
End If
End If
End If
Next
Next mo

disks.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub RegisterHidNotification()
Dim dbi As DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE = New
DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
Dim gd As Guid
' MsgBox(Marshal.SizeOf(gd))
' MsgBox(Marshal.SizeOf(New
Win32.DEV_BROADCAST_DEVICEINTERFACE))
dbi.dbcc_size = size
dbi.dbcc_devicetype = DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE
dbi.dbcc_reserved = 0
dbi.dbcc_classguid = DeviceDetector.GUID_IO_MEDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = DeviceDetector.RegisterDeviceNotification(Handle, Buffer,
DeviceDetector.DEVICE_NOTIFY_WINDOW_HANDLE)
Marshal.PtrToStructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToInt32 Then
'MessageBox.Show(DeviceDetector.GetLastError().ToS tring())
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = DeviceDetector.WM_DEVICECHANGE Then
OnDeviceChange(m)
End If
MyBase.WndProc(m)
End Sub
Private Sub OnDeviceChange(ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToInt32()
If wParam = DeviceDetector.DBT_DEVICEARRIVAL Then

Dim o As New DeviceDetector.DEV_BROADCAST_HDR
Dim b As New DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE1
Dim gd As Guid
Marshal.PtrToStructure(msg.LParam, o)
If (o.dbcc_devicetype =
DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE) Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(strsize)
Marshal.PtrToStructure(msg.LParam, b)
Dim str As New String(b.dbcc_name, 0, strsize)
'***********************************************
' Device Arrival
'***********************************************
Arrival()
End If
ElseIf wParam = DeviceDetector.DBT_DEVICEREMOVECOMPLETE Then
'***********************************************
' Device Removal
'***********************************************
Removal()
End If
End Sub
Private Class DeviceDetector
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIVAL = &H8000
Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_WINDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_SERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVICEINTERFACE = 5
Public Shared GUID_IO_MEDIA_ARRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
_
Public Class DEV_BROADCAST_DEVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(UnmanagedType.ByValArray,
ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Public dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> _
Public dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_HDR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class
<DllImport("user32.DLL", SetLastError:=True)> _
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal
NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
<DllImport("kernel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class
End Class

Mar 4 '06 #2
Hi,

You are getting the error with your code because you are calling the
wmi from the wrong thread. Use control.invoke to get the wmi call on the
right thread.

Ken
--------------------------

"Ken Tucker [MVP]" wrote:
Hi,

Why dont you let the wmi tell you when the usb drive is inserted?

http://www.vb-tips.com/default.aspx?...a-07a4ef9d9504

Ken
-------------------
"Chad" <ch********@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
To anyone who is smarter than I am when it comes to WMI:

Here is what I am trying to do:

1) Detect a USB pen drive when it is inserted
2) Retrieve the drive letter of the pen drive
3) Check for a specific folder on the pen drive

I keep receiving an error message that reads:
An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll

The detection of the USB drive is working correctly, and it calls a
method called Arrival(). Within that method I call a CheckDrive()
method that is supposed to loop through all of the logical disks and
find a removable drive that contains a specific folder. I have also
gotten a System.ExecutionEngineException when the application gets to
the following line of code:

Dim moc As ManagementObjectCollection = disks.GetInstances()

I have also received a "Catastrophic Failure" message when this
same code is used in another conceptual application I wrote.

Is there a better way to do this, maybe I am going about it the wrong
way. Any help would be greatly appreciated.

Here is my code, I am using the DotNetFramework 1.1:

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Text
Imports System.management
Imports System.IO
Public Class DetectorForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
RegisterHidNotification()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DetectorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 333)
Me.Name = "DetectorForm"
Me.Text = "DetectorForm"

End Sub

#End Region
Private Sub Arrival()
MsgBox("Arrival")
CheckDrive()
End Sub

Private Sub Removal()
MsgBox("Removal")
End Sub
Public Sub CheckDrive()
Try
Dim disks As New ManagementClass("Win32_LogicalDisk")
Dim moc As ManagementObjectCollection =
disks.GetInstances()
Dim mo As ManagementObject
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty As PropertyData
Dim removableDisk As ManagementObject

'For each LogicalDisk on the Computer
For Each mo In moc
'Retrieve the disk's properties
DiskProperties = mo.Properties
'Iterate through the disk's properties
For Each DiskProperty In DiskProperties
'Check whether the particular property is defined
for this drive
If Not IsNothing(DiskProperty.Value) Then
'Check if the drive is removable DriveType=2 -
Removable
If DiskProperty.Name.ToString = "DriveType" _
And DiskProperty.Value.ToString = "2" Then
'Check if this Removable disk is a Zoom
Drive
Dim drvLetter As String
drvLetter =
mo.Properties("DeviceId").Value.ToString()
'Check if a directory exists
If Directory.Exists(drvLetter &
"chadc3322") Then
MsgBox("chadc3322 Exists")
Exit For
End If
End If
End If
Next
Next mo

disks.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub RegisterHidNotification()
Dim dbi As DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE = New
DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
Dim gd As Guid
' MsgBox(Marshal.SizeOf(gd))
' MsgBox(Marshal.SizeOf(New
Win32.DEV_BROADCAST_DEVICEINTERFACE))
dbi.dbcc_size = size
dbi.dbcc_devicetype = DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE
dbi.dbcc_reserved = 0
dbi.dbcc_classguid = DeviceDetector.GUID_IO_MEDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = DeviceDetector.RegisterDeviceNotification(Handle, Buffer,
DeviceDetector.DEVICE_NOTIFY_WINDOW_HANDLE)
Marshal.PtrToStructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToInt32 Then
'MessageBox.Show(DeviceDetector.GetLastError().ToS tring())
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = DeviceDetector.WM_DEVICECHANGE Then
OnDeviceChange(m)
End If
MyBase.WndProc(m)
End Sub
Private Sub OnDeviceChange(ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToInt32()
If wParam = DeviceDetector.DBT_DEVICEARRIVAL Then

Dim o As New DeviceDetector.DEV_BROADCAST_HDR
Dim b As New DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE1
Dim gd As Guid
Marshal.PtrToStructure(msg.LParam, o)
If (o.dbcc_devicetype =
DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE) Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(strsize)
Marshal.PtrToStructure(msg.LParam, b)
Dim str As New String(b.dbcc_name, 0, strsize)
'***********************************************
' Device Arrival
'***********************************************
Arrival()
End If
ElseIf wParam = DeviceDetector.DBT_DEVICEREMOVECOMPLETE Then
'***********************************************
' Device Removal
'***********************************************
Removal()
End If
End Sub
Private Class DeviceDetector
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIVAL = &H8000
Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_WINDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_SERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVICEINTERFACE = 5
Public Shared GUID_IO_MEDIA_ARRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
_
Public Class DEV_BROADCAST_DEVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(UnmanagedType.ByValArray,
ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Public dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> _
Public dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_HDR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class
<DllImport("user32.DLL", SetLastError:=True)> _
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal
NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
<DllImport("kernel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class
End Class


Mar 4 '06 #3
That VB Tips website is so full of bugs & the code examples don't compile.
Take the webcam capture example: In the click event of button 1, it hasn't a
correct API signature for it

As for clicking a slow opening VB tip, then click the LINKS option on the
left & it shows a tip & the links. If you click back on the tips then you
get two tips.

The site was written by someone who 1) cannot write VB (so-called MVP's) &
2) has no concept of ASPX coding

A MVP should effectively know what they are talking about, but this site
demonstrates that these two people obviously don't


"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Hi,

Why dont you let the wmi tell you when the usb drive is inserted?

http://www.vb-tips.com/default.aspx?...a-07a4ef9d9504
Ken
-------------------
"Chad" <ch********@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
To anyone who is smarter than I am when it comes to WMI:

Here is what I am trying to do:

1) Detect a USB pen drive when it is inserted
2) Retrieve the drive letter of the pen drive
3) Check for a specific folder on the pen drive

I keep receiving an error message that reads:
An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll

The detection of the USB drive is working correctly, and it calls a
method called Arrival(). Within that method I call a CheckDrive()
method that is supposed to loop through all of the logical disks and
find a removable drive that contains a specific folder. I have also
gotten a System.ExecutionEngineException when the application gets to
the following line of code:

Dim moc As ManagementObjectCollection = disks.GetInstances()

I have also received a "Catastrophic Failure" message when this
same code is used in another conceptual application I wrote.

Is there a better way to do this, maybe I am going about it the wrong
way. Any help would be greatly appreciated.

Here is my code, I am using the DotNetFramework 1.1:

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Text
Imports System.management
Imports System.IO
Public Class DetectorForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
RegisterHidNotification()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DetectorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 333)
Me.Name = "DetectorForm"
Me.Text = "DetectorForm"

End Sub

#End Region
Private Sub Arrival()
MsgBox("Arrival")
CheckDrive()
End Sub

Private Sub Removal()
MsgBox("Removal")
End Sub
Public Sub CheckDrive()
Try
Dim disks As New ManagementClass("Win32_LogicalDisk")
Dim moc As ManagementObjectCollection =
disks.GetInstances()
Dim mo As ManagementObject
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty As PropertyData
Dim removableDisk As ManagementObject

'For each LogicalDisk on the Computer
For Each mo In moc
'Retrieve the disk's properties
DiskProperties = mo.Properties
'Iterate through the disk's properties
For Each DiskProperty In DiskProperties
'Check whether the particular property is defined
for this drive
If Not IsNothing(DiskProperty.Value) Then
'Check if the drive is removable DriveType=2 -
Removable
If DiskProperty.Name.ToString = "DriveType" _
And DiskProperty.Value.ToString = "2" Then
'Check if this Removable disk is a Zoom
Drive
Dim drvLetter As String
drvLetter =
mo.Properties("DeviceId").Value.ToString()
'Check if a directory exists
If Directory.Exists(drvLetter &
"chadc3322") Then
MsgBox("chadc3322 Exists")
Exit For
End If
End If
End If
Next
Next mo

disks.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub RegisterHidNotification()
Dim dbi As DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE = New
DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
Dim gd As Guid
' MsgBox(Marshal.SizeOf(gd))
' MsgBox(Marshal.SizeOf(New
Win32.DEV_BROADCAST_DEVICEINTERFACE))
dbi.dbcc_size = size
dbi.dbcc_devicetype = DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE
dbi.dbcc_reserved = 0
dbi.dbcc_classguid = DeviceDetector.GUID_IO_MEDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = DeviceDetector.RegisterDeviceNotification(Handle, Buffer,
DeviceDetector.DEVICE_NOTIFY_WINDOW_HANDLE)
Marshal.PtrToStructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToInt32 Then
'MessageBox.Show(DeviceDetector.GetLastError().ToS tring())
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = DeviceDetector.WM_DEVICECHANGE Then
OnDeviceChange(m)
End If
MyBase.WndProc(m)
End Sub
Private Sub OnDeviceChange(ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToInt32()
If wParam = DeviceDetector.DBT_DEVICEARRIVAL Then

Dim o As New DeviceDetector.DEV_BROADCAST_HDR
Dim b As New DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE1
Dim gd As Guid
Marshal.PtrToStructure(msg.LParam, o)
If (o.dbcc_devicetype =
DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE) Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(strsize)
Marshal.PtrToStructure(msg.LParam, b)
Dim str As New String(b.dbcc_name, 0, strsize)
'***********************************************
' Device Arrival
'***********************************************
Arrival()
End If
ElseIf wParam = DeviceDetector.DBT_DEVICEREMOVECOMPLETE Then
'***********************************************
' Device Removal
'***********************************************
Removal()
End If
End Sub
Private Class DeviceDetector
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIVAL = &H8000
Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_WINDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_SERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVICEINTERFACE = 5
Public Shared GUID_IO_MEDIA_ARRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
_
Public Class DEV_BROADCAST_DEVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(UnmanagedType.ByValArray,
ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Public dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> _
Public dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_HDR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class
<DllImport("user32.DLL", SetLastError:=True)> _
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal
NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
<DllImport("kernel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class
End Class


Mar 5 '06 #4
I still get the same error when I call using the Invoke method. I
added the following code:

'Declaring the Delegates for arrival and removal
Delegate Sub DiskArrival()
Delegate Sub DiskRemoval()

'For the calling of the Arrival and Removal Methods I modified to be
the following
Me.Invoke(New DiskArrival(AddressOf Arrival))
Me.Invoke(New DiskRemoval(AddressOf Removal))

I get (An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll)

Am I calling the method wrong? I have also tried invoking the
CheckDrive method the same way, and I get the same error.

Thanks

Mar 6 '06 #5
Chad,

I figured it out. When the checkdisk procedure is running the wmi
is still adding the new drive to the list. That is the reason for the error.
I tried a bunch of differnet ways but wound up adding a timer to the form.
I enable the timer in the arrive procedure. In the timer event I call the
checkdrive and disable the timer. The timer gives the wmi a chance to do its
thing.

Private Sub Arrival()
MsgBox("Arrival")
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
CheckDrive()
Timer1.Enabled = False
End Sub

Ken
------------------
"Chad" wrote:
I still get the same error when I call using the Invoke method. I
added the following code:

'Declaring the Delegates for arrival and removal
Delegate Sub DiskArrival()
Delegate Sub DiskRemoval()

'For the calling of the Arrival and Removal Methods I modified to be
the following
Me.Invoke(New DiskArrival(AddressOf Arrival))
Me.Invoke(New DiskRemoval(AddressOf Removal))

I get (An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll)

Am I calling the method wrong? I have also tried invoking the
CheckDrive method the same way, and I get the same error.

Thanks

Mar 7 '06 #6
Excellent! It works like a charm.
Thanks for your help Ken.

Chad

Mar 7 '06 #7
Instead of being a pontificating braggadocio, why don't you try and be
constructive with your criticism and offer solutions as opposed to just being
a blow hard.
--
Steve Kemp MCSE
"LOL @ The MVPs" wrote:
That VB Tips website is so full of bugs & the code examples don't compile.
Take the webcam capture example: In the click event of button 1, it hasn't a
correct API signature for it

As for clicking a slow opening VB tip, then click the LINKS option on the
left & it shows a tip & the links. If you click back on the tips then you
get two tips.

The site was written by someone who 1) cannot write VB (so-called MVP's) &
2) has no concept of ASPX coding

A MVP should effectively know what they are talking about, but this site
demonstrates that these two people obviously don't


"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Hi,

Why dont you let the wmi tell you when the usb drive is inserted?

http://www.vb-tips.com/default.aspx?...a-07a4ef9d9504

Ken
-------------------
"Chad" <ch********@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
To anyone who is smarter than I am when it comes to WMI:

Here is what I am trying to do:

1) Detect a USB pen drive when it is inserted
2) Retrieve the drive letter of the pen drive
3) Check for a specific folder on the pen drive

I keep receiving an error message that reads:
An unhandled exception of type 'System.ExecutionEngineException'
occurred in system.management.dll

The detection of the USB drive is working correctly, and it calls a
method called Arrival(). Within that method I call a CheckDrive()
method that is supposed to loop through all of the logical disks and
find a removable drive that contains a specific folder. I have also
gotten a System.ExecutionEngineException when the application gets to
the following line of code:

Dim moc As ManagementObjectCollection = disks.GetInstances()

I have also received a "Catastrophic Failure" message when this
same code is used in another conceptual application I wrote.

Is there a better way to do this, maybe I am going about it the wrong
way. Any help would be greatly appreciated.

Here is my code, I am using the DotNetFramework 1.1:

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Text
Imports System.management
Imports System.IO
Public Class DetectorForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
RegisterHidNotification()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DetectorForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 333)
Me.Name = "DetectorForm"
Me.Text = "DetectorForm"

End Sub

#End Region
Private Sub Arrival()
MsgBox("Arrival")
CheckDrive()
End Sub

Private Sub Removal()
MsgBox("Removal")
End Sub
Public Sub CheckDrive()
Try
Dim disks As New ManagementClass("Win32_LogicalDisk")
Dim moc As ManagementObjectCollection =
disks.GetInstances()
Dim mo As ManagementObject
Dim DiskProperties As PropertyDataCollection
Dim DiskProperty As PropertyData
Dim removableDisk As ManagementObject

'For each LogicalDisk on the Computer
For Each mo In moc
'Retrieve the disk's properties
DiskProperties = mo.Properties
'Iterate through the disk's properties
For Each DiskProperty In DiskProperties
'Check whether the particular property is defined
for this drive
If Not IsNothing(DiskProperty.Value) Then
'Check if the drive is removable DriveType=2 -
Removable
If DiskProperty.Name.ToString = "DriveType" _
And DiskProperty.Value.ToString = "2" Then
'Check if this Removable disk is a Zoom
Drive
Dim drvLetter As String
drvLetter =
mo.Properties("DeviceId").Value.ToString()
'Check if a directory exists
If Directory.Exists(drvLetter &
"chadc3322") Then
MsgBox("chadc3322 Exists")
Exit For
End If
End If
End If
Next
Next mo

disks.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub RegisterHidNotification()
Dim dbi As DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE = New
DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE
Dim size As Integer
size = Marshal.SizeOf(dbi)
Dim gd As Guid
' MsgBox(Marshal.SizeOf(gd))
' MsgBox(Marshal.SizeOf(New
Win32.DEV_BROADCAST_DEVICEINTERFACE))
dbi.dbcc_size = size
dbi.dbcc_devicetype = DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE
dbi.dbcc_reserved = 0
dbi.dbcc_classguid = DeviceDetector.GUID_IO_MEDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHGlobal(size)
Marshal.StructureToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = DeviceDetector.RegisterDeviceNotification(Handle, Buffer,
DeviceDetector.DEVICE_NOTIFY_WINDOW_HANDLE)
Marshal.PtrToStructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToInt32 Then
'MessageBox.Show(DeviceDetector.GetLastError().ToS tring())
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = DeviceDetector.WM_DEVICECHANGE Then
OnDeviceChange(m)
End If
MyBase.WndProc(m)
End Sub
Private Sub OnDeviceChange(ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToInt32()
If wParam = DeviceDetector.DBT_DEVICEARRIVAL Then

Dim o As New DeviceDetector.DEV_BROADCAST_HDR
Dim b As New DeviceDetector.DEV_BROADCAST_DEVICEINTERFACE1
Dim gd As Guid
Marshal.PtrToStructure(msg.LParam, o)
If (o.dbcc_devicetype =
DeviceDetector.DBT_DEVTYP_DEVICEINTERFACE) Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(strsize)
Marshal.PtrToStructure(msg.LParam, b)
Dim str As New String(b.dbcc_name, 0, strsize)
'***********************************************
' Device Arrival
'***********************************************
Arrival()
End If
ElseIf wParam = DeviceDetector.DBT_DEVICEREMOVECOMPLETE Then
'***********************************************
' Device Removal
'***********************************************
Removal()
End If
End Sub
Private Class DeviceDetector
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIVAL = &H8000
Public Const DBT_DEVICEREMOVECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_WINDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_SERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVICEINTERFACE = 5
Public Shared GUID_IO_MEDIA_ARRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_DEVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
_
Public Class DEV_BROADCAST_DEVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(UnmanagedType.ByValArray,
ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Public dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> _
Public dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Class DEV_BROADCAST_HDR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class
<DllImport("user32.DLL", SetLastError:=True)> _
Public Shared Function _
RegisterDeviceNotification(ByVal IntPtr As IntPtr, ByVal
NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function
<DllImport("kernel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class
End Class



Mar 28 '06 #8
Hi Chad,

I'm trying to do something very similar. Earlier in the thread Ken Tucker
asked why you don't use a WMI 'ManagementEventWatcher' to watch for new
devices? I was wondering the same thing. Do you have a specific reason?

Chris

"Chad" wrote:
Excellent! It works like a charm.
Thanks for your help Ken.

Chad

Mar 30 '06 #9

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

Similar topics

3
by: Christopher Mouton | last post by:
We regularly make drive images of our entire server and store it at a backup site. To be honest I have never fully understood how the imaging programs deal with open files. My question is will the...
4
by: sanjana | last post by:
hi i m using the win32_diskdrive class for detecting a memory card insertion and removal..and this class detects memory card(sd card..etc) insertion removal from the device the deviceid...
5
by: Dave H | last post by:
I have an asp:listbox, allowing multiple selections, is there a quick check to see if there's more than one selected, or do I need to go through the whole list? Thanks, Dave
2
by: kj7ny | last post by:
I am attempting to incrementally back up files using python. How can I compare a file on a hard drive to a file in a python created zip file to tell if the file has changed? Or should I be using...
3
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, Could someone tell me how to retrieve a drive's drive letter from user mode given its device name? Any information is greatly appreciated. Thanks, Priya
3
by: Newbie19 | last post by:
I am trying to retrieve information from a remote Network drive using Visual Basic... however I am unable to retrieve any data. I'm trying to integrate into a ASP.Net page that already runs an SQL...
1
by: Newbie19 | last post by:
I am currently making an ASP.Net application that uses SQL to pull data from a database and displays the information from the db on the page. However, I've been asked to pull information from a...
0
by: origami.takarana | last post by:
Intrusion Detection Strategies ----------------------------------- Until now, we’ve primarily discussed monitoring in how it relates to intrusion detection, but there’s more to an overall...
10
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.