Documentation ¶
Index ¶
- Constants
- Variables
- func DevconDisableDevice(devconPath string, deviceName string) (int, error)
- func DevconEnableDevice(devconPath string, deviceName string) (int, error)
- func DevconRemoveDevice(devconPath string, deviceName string) (int, error)
- func DiskPartAssignVolumeMountPoint(num uint, volumeLetter byte) error
- func DiskPartIsDiskReadOnly(diskNum uint) (bool, error)
- func DiskPartIsVolumeReadOnly(diskLetter byte) (bool, error)
- func DiskPartRemoveVolumeMountPoint(volumeLetter byte) error
- func DiskPartSetDiskReadOnly(diskNum uint) error
- func DiskPartSetDiskReadWrite(diskNum uint) error
- func DiskPartSwitchDiskReadOnly(diskNum uint) error
- func GetUSBHistoryQuantity() (num int, err error)
- func GetUsbPhysicalDiskCount() (int, error)
- func GetVolumeLetterByVolumeGUID(guid string) (string, error)
- func MountvolDisableAutoMount() error
- func MountvolEnableAutoMount() error
- func MountvolRemoveMountPoint(volumeLetter byte) error
- func MountvolRemoveUnusedMountPoint() error
- func PnputilEnumConnectedDevices() ([][]doraemon.Pair[string, string], error)
- func RegisterDeviceNotification(hwnd windows.HWND) error
- func RegistryDisableAllUsb() error
- func RegistryEnableAllUsb() error
- func RegistryGetAllUsbReadOnly() (bool, bool, error)
- func RegistryGetAllUsbStatus() (uint, error)
- func RegistrySetAllUsbReadOnly() error
- func RegistrySetAllUsbReadWrite() error
- func WatchUsbDevice(callback func(UsbDeviceBehavior, uintptr)) error
- func WmicGetPhysicalDiskCount() (int, error)
- func WndProc(hWnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
- type DevBroadcastDevinterface
- type DeviceInfo
- type DiskPartDiskDetail
- type DiskPartDiskInfo
- type DiskPartVolumeInfo
- type MSG
- type POINT
- type UsbDevInfo
- type UsbDeviceBehavior
- type WmicDeviceInfo
- type Wndclassex
Constants ¶
const ( // https://docs.microsoft.com/en-us/windows/win32/devio/wm-devicechange // https://godoc.org/github.com/AllenDang/w32#WM_DEVICECHANGE WM_DEVICECHANGE = 537 // https://godoc.org/github.com/AllenDang/w32#HWND_MESSAGE HWND_MESSAGE = ^uintptr(2) // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerdevicenotificationa#device_notify_all_interface_classes DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 4 // https://docs.microsoft.com/en-us/windows/win32/api/dbt/ns-dbt-_dev_broadcast_hdr#DBT_DEVTYP_DEVICEINTERFACE DBT_DEVTYP_DEVICEINTERFACE = 5 // https://docs.microsoft.com/en-us/windows/win32/devio/wm-devicechange#DBT_DEVICEARRIVAL DBT_DEVICEARRIVAL = 0x8000 // https://docs.microsoft.com/en-us/windows/win32/devio/wm-devicechange#DBT_DEVICEREMOVECOMPLETE DBT_DEVICEREMOVECOMPLETE = 0x8004 )
const ( DBT_DEVICEQUERYREMOVE = 0x8001 // wants to remove, may fail DBT_DEVICEQUERYREMOVEFAILED = 0x8002 // removal aborted DBT_DEVICEREMOVEPENDING = 0x8003 // about to remove, still avail. DBT_DEVICETYPESPECIFIC = 0x8005 // type specific event DEVICE_NOTIFY_WINDOW_HANDLE = 0x0 )
Variables ¶
var GUID_DEVINTERFACE_USB_DEVICE = windows.GUID{ Data1: 0xa5dcbf10, Data2: 0x6530, Data3: 0x11d2, Data4: [8]byte{0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}, }
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/guid-devinterface-usb-device A5DCBF10-6530-11D2-901F-00C04FB951ED
var HID_DEVICE_CLASS = windows.GUID{ Data1: 0x745a17a0, Data2: 0x74d3, Data3: 0x11d0, Data4: [8]byte{0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda}, }
https://www.lifewire.com/device-class-guids-for-most-common-types-of-hardware-2619208 745A17A0-74D3-11D0-B6FE-00A0C90F57DA
var ( SMARTCARD_DEVICE_CLASS = windows.GUID{ Data1: 0xDEEBE6AD, Data2: 0x9E01, Data3: 0x47E2, Data4: [8]byte{0xA3, 0xB2, 0xA6, 0x6A, 0xA2, 0xC0, 0x36, 0xC9}, } )
Functions ¶
func DevconDisableDevice ¶
disable后需要Enable才能恢复。 deviceName: *VID_8087&PID_1024*
func DevconEnableDevice ¶
deviceName: *VID_8087&PID_1024*
func DevconRemoveDevice ¶
重新插拔后即可恢复,需要管理员。 deviceName: *VID_8087&PID_1024*
func DiskPartAssignVolumeMountPoint ¶
分配卷装载点,volumeLetter为0则自动分配
func DiskPartIsDiskReadOnly ¶
磁盘是否只读,需要管理员权限
func DiskPartIsVolumeReadOnly ¶
是否只读,需要管理员权限
func DiskPartRemoveVolumeMountPoint ¶
删除卷装载点,删除后不会在下次启动时自动装载。 仅限于此U盘,重新插入也不会自动装载。 恢复使用diskpart assign
func DiskPartSwitchDiskReadOnly ¶
切换磁盘只读/可读写状态,需要管理员权限
func GetUSBHistoryQuantity ¶
检查在 Windows 系统上曾经挂载过的 USB 设备的数量
func MountvolRemoveMountPoint ¶
删除指定的卷的装入点目录和注册表设置。 仅限于此U盘,重新插入也不会自动装载。 恢复使用diskpart assign
func MountvolRemoveUnusedMountPoint ¶
func MountvolRemoveUnusedMountPoint() error
删除不在系统中的、卷的装入点目录和注册表设置。
func PnputilEnumConnectedDevices ¶
枚举系统上已连接的设备
func RegisterDeviceNotification ¶
代码修改自:https://github.com/unreality/nCryptAgent/blob/master/deviceevents/events.go
func RegistryGetAllUsbReadOnly ¶
返回状态(只读/可读写), key是否存在, error。 需要管理员权限
func RegistryGetAllUsbStatus ¶
需要管理员权限, 可能需要重启
0x00000004(4) 禁用 0x00000003(3) 启用 0x00000002(2) 自动 0x00000001(1) 系统
func WatchUsbDevice ¶
func WatchUsbDevice(callback func(UsbDeviceBehavior, uintptr)) error
监控usb设备插拔。 代码修改自:https://github.com/jake-dog/opensimdash
Types ¶
type DevBroadcastDevinterface ¶
type DevBroadcastDevinterface struct {
// contains filtered or unexported fields
}
https://docs.microsoft.com/en-us/windows/win32/api/dbt/ns-dbt-_dev_broadcast_deviceinterface_a
type DeviceInfo ¶
func DevconListAllBluetoothDeviceNames ¶
func DevconListAllBluetoothDeviceNames(devconPath string) ([]DeviceInfo, error)
列出所有蓝牙设备(包括曾经的)
func DevconListAllDeviceNames ¶
func DevconListAllDeviceNames(devconPath string) ([]DeviceInfo, error)
列出电脑上全部的设备名称和描述(包括曾经的)。
func DevconListAllUsbDeviceNames ¶
func DevconListAllUsbDeviceNames(devconPath string) ([]DeviceInfo, error)
列出所有的USB设备名称
type DiskPartDiskDetail ¶
type DiskPartDiskDetail struct { Desc string Volume []DiskPartVolumeInfo // contains filtered or unexported fields }
DISKPART> detail disk
Generic Masstorage USB Device 磁盘 ID: 00000000 类型 : USB 状态 : 联机 路径 : 0 目标 : 0 LUN ID : 0 位置路径 : UNAVAILABLE 当前只读状态: 否 只读: 否 启动磁盘: 否 页面文件磁盘: 否 休眠文件磁盘: 否 故障转储磁盘: 否 群集磁盘 : 否
卷 ### LTR 标签 FS 类型 大小 状态 信息 ---------- --- ----------- ----- ---------- ------- --------- -------- 卷 4 F FAT32 可移动 29 GB 正常
func DiskPartDetailDisk ¶
func DiskPartDetailDisk(diskNumber uint) (DiskPartDiskDetail, error)
需要管理员权限
type DiskPartDiskInfo ¶
type DiskPartDiskInfo struct { // 磁盘 0 Number string // 联机 Status string Size string Free string Dyn string Gpt string }
磁盘 ### 状态 大小 可用 Dyn Gpt -------- ------------- ------- ------- --- --- 磁盘 0 联机 931 GB 1024 KB * 磁盘 1 联机 931 GB 7375 MB * 磁盘 2 联机 29 GB 3072 KB
type DiskPartVolumeInfo ¶
type DiskPartVolumeInfo struct { // 0 Number string // C Ltr string Label string Fs string Type string Size string Status string Info string }
卷 ### LTR 标签 FS 类型 大小 状态 信息 ---------- --- ----------- ----- ---------- ------- --------- -------- 卷 0 E 新加卷 NTFS 磁盘分区 931 GB 正常 卷 1 C system NTFS 磁盘分区 459 GB 正常 启动 卷 2 D data NTFS 磁盘分区 464 GB 正常 卷 3 FAT32 磁盘分区 599 MB 正常 系统 卷 4 F FAT32 可移动 29 GB 正常
type MSG ¶
type MSG struct {
// contains filtered or unexported fields
}
https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-tagmsg
type POINT ¶
type POINT struct {
// contains filtered or unexported fields
}
https://docs.microsoft.com/en-us/previous-versions//dd162805(v=vs.85)
type UsbDevInfo ¶
type UsbDevInfo struct { DbccSize uint32 DbccDeviceType uint32 DbccReserved uint32 Name string GUID windows.GUID }
func ReadDeviceInfo ¶
func ReadDeviceInfo(devInfoPtr uintptr) (UsbDevInfo, error)
代码修改自:https://github.com/unreality/nCryptAgent/blob/master/deviceevents/events.go
type UsbDeviceBehavior ¶
type UsbDeviceBehavior int
const ( AddDevice UsbDeviceBehavior = iota RemoveDevice Unknown )
func (UsbDeviceBehavior) String ¶
func (behavior UsbDeviceBehavior) String() string
type WmicDeviceInfo ¶
type Wndclassex ¶
type Wndclassex struct { Size uint32 Style uint32 WndProc uintptr ClsExtra int32 WndExtra int32 Instance syscall.Handle Icon syscall.Handle Cursor syscall.Handle Background syscall.Handle MenuName *uint16 ClassName *uint16 IconSm syscall.Handle }
https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-tagwndclassexa https://golang.org/src/runtime/syscall_windows_test.go