device

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
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

View Source
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

View Source
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

View Source
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

func DevconDisableDevice(devconPath string, deviceName string) (int, error)

disable后需要Enable才能恢复。 deviceName: *VID_8087&PID_1024*

func DevconEnableDevice

func DevconEnableDevice(devconPath string, deviceName string) (int, error)

deviceName: *VID_8087&PID_1024*

func DevconRemoveDevice

func DevconRemoveDevice(devconPath string, deviceName string) (int, error)

重新插拔后即可恢复,需要管理员。 deviceName: *VID_8087&PID_1024*

func DiskPartAssignVolumeMountPoint

func DiskPartAssignVolumeMountPoint(num uint, volumeLetter byte) error

分配卷装载点,volumeLetter为0则自动分配

func DiskPartIsDiskReadOnly

func DiskPartIsDiskReadOnly(diskNum uint) (bool, error)

磁盘是否只读,需要管理员权限

func DiskPartIsVolumeReadOnly

func DiskPartIsVolumeReadOnly(diskLetter byte) (bool, error)

是否只读,需要管理员权限

func DiskPartRemoveVolumeMountPoint

func DiskPartRemoveVolumeMountPoint(volumeLetter byte) error

删除卷装载点,删除后不会在下次启动时自动装载。 仅限于此U盘,重新插入也不会自动装载。 恢复使用diskpart assign

func DiskPartSetDiskReadOnly

func DiskPartSetDiskReadOnly(diskNum uint) error

设置磁盘为只读,需要管理员权限

func DiskPartSetDiskReadWrite

func DiskPartSetDiskReadWrite(diskNum uint) error

设置磁盘为可读写,需要管理员权限

func DiskPartSwitchDiskReadOnly

func DiskPartSwitchDiskReadOnly(diskNum uint) error

切换磁盘只读/可读写状态,需要管理员权限

func GetUSBHistoryQuantity

func GetUSBHistoryQuantity() (num int, err error)

检查在 Windows 系统上曾经挂载过的 USB 设备的数量

func GetUsbPhysicalDiskCount

func GetUsbPhysicalDiskCount() (int, error)

USB物理存储设备的个数(不包括分区)

func GetVolumeLetterByVolumeGUID

func GetVolumeLetterByVolumeGUID(guid string) (string, error)

func MountvolDisableAutoMount

func MountvolDisableAutoMount() error

禁用新卷的自动装入。

func MountvolEnableAutoMount

func MountvolEnableAutoMount() error

再次启用新卷的自动装入。

func MountvolRemoveMountPoint

func MountvolRemoveMountPoint(volumeLetter byte) error

删除指定的卷的装入点目录和注册表设置。 仅限于此U盘,重新插入也不会自动装载。 恢复使用diskpart assign

func MountvolRemoveUnusedMountPoint

func MountvolRemoveUnusedMountPoint() error

删除不在系统中的、卷的装入点目录和注册表设置。

func PnputilEnumConnectedDevices

func PnputilEnumConnectedDevices() ([][]doraemon.Pair[string, string], error)

枚举系统上已连接的设备

func RegistryDisableAllUsb

func RegistryDisableAllUsb() error

需要管理员权限, 可能需要重启

func RegistryEnableAllUsb

func RegistryEnableAllUsb() error

需要管理员权限, 可能需要重启

func RegistryGetAllUsbReadOnly

func RegistryGetAllUsbReadOnly() (bool, bool, error)

返回状态(只读/可读写), key是否存在, error。 需要管理员权限

func RegistryGetAllUsbStatus

func RegistryGetAllUsbStatus() (uint, error)

需要管理员权限, 可能需要重启

0x00000004(4) 禁用 0x00000003(3) 启用 0x00000002(2) 自动 0x00000001(1) 系统

func RegistrySetAllUsbReadOnly

func RegistrySetAllUsbReadOnly() error

设置全部usb设备为只读, 需要管理员权限

func RegistrySetAllUsbReadWrite

func RegistrySetAllUsbReadWrite() error

设置全部usb设备为可读写, 需要管理员权限

func WatchUsbDevice

func WatchUsbDevice(callback func(UsbDeviceBehavior, uintptr)) error

监控usb设备插拔。 代码修改自:https://github.com/jake-dog/opensimdash

func WmicGetPhysicalDiskCount

func WmicGetPhysicalDiskCount() (int, error)

物理存储设备的个数(不包括分区)

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

type DeviceInfo struct {
	Name string
	Desc string
}

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

func DiskPartListDisk

func DiskPartListDisk() ([]DiskPartDiskInfo, error)

需要管理员权限

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 正常

func DiskPartListVolume

func DiskPartListVolume() ([]DiskPartVolumeInfo, error)

需要管理员权限

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
}

type UsbDeviceBehavior

type UsbDeviceBehavior int
const (
	AddDevice UsbDeviceBehavior = iota
	RemoveDevice
	Unknown
)

func (UsbDeviceBehavior) String

func (behavior UsbDeviceBehavior) String() string

type WmicDeviceInfo

type WmicDeviceInfo struct {
	Name        string
	Caption     string
	DeviceID    string
	PNPDeviceID string
	Status      string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL