c u盤使用記錄 C 檢測是否有u盤插入的方法

2021-10-13 02:28:59 字數 1473 閱讀 6593

該c#**可監控是否有u盤插入,同時可以監控其它驅動器的變化

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.text;

using system.windows.forms;

using system.runtime.interopservices

public partial class form1 : form

public form1()

initializecomponent();

[structlayout(layoutkind.sequential)]

public struct dev_broadcast_volume

public int dbcv_size;

public int dbcv_devicetype;

public int dbcv_reserved;

public int dbcv_unitmask;

protected override void wndproc(ref message m)

// 發生裝置變動

const int wm_devicechange = 0x0219;

// 系統檢測到乙個新裝置

const int dbt_devicearrival = 0x8000;

// 系統完成移除乙個裝置

const int dbt_deviceremovecomplete = 0x8001;

// 邏輯卷標

const int dbt_devtyp_volume = 0x00000002;

switch (m.msg)

case wm_devicechange:

switch (m.wparam.toint32())

case dbt_devicearrival:

int devtype = marshal.readint32(m.lparam, 4);

if (devtype == dbt_devtyp_volume)

dev_broadcast_volume vol;

vol = (dev_broadcast_volume)marshal.ptrtostructure(

m.lparam, typeof(dev_broadcast_volume));

messagebox.show(vol.dbcv_unitmask.tostring("x"));

break;

case dbt_deviceremovecomplete:

messagebox.show("removal");

break;

break;

base.wndproc(ref m);

c u盤使用記錄 C 如何讀取U盤中的檔案啊

找到了 當把u盤放插入,然後程式自動將u盤的內容複製到本地硬碟 using system using system.collections.generic using using system.data using system.drawing using system.text using sys...

檢測是否存在u盤碟符

主要的功能函式如下 uses uselectdriveremovable procedure tform20.formcreate sender tobject begin btn tosd.enabled chkdriveremovable end u盤的 插入和刪除windows會給所有的程式發...

Windows 檢測碟符是否為U盤

storage property query結構體 typedef struct storage property query storage property query,pstorage property query 用於儲存將要查詢的碟符裝置的屬性 storage device descrip...