Detect drive mount event in c#

前端 未结 1 1677
花落未央
花落未央 2021-02-14 21:03

How to catch an event when a new drive is added to My Computer and preferably and when new mount point for some drive is created on a NTFS drive?


I figued out this

1条回答
  •  不思量自难忘°
    2021-02-14 21:47

    If you have a form, you can override its WndProc method to catch WM_DEVICECHANGE messages as Eugene mentioned:

    private const int WM_DEVICECHANGE = 0x219;
    
    protected override void WndProc(ref Message m)
    {
        base.WndProc(m);
    
        if (m.Msg == WM_DEVICECHANGE)
        {
            // Check m.wParam to see exactly what happened
        }
    }
    

    0 讨论(0)
提交回复
热议问题