deviceiocontrol

SMART_RCV_DRIVE_DATA DeviceIoControl ERROR_ACCESS_DENIED

有些话、适合烂在心里 提交于 2020-03-25 15:16:09
问题 When calling DeviceIoControl with SMART_RCV_DRIVE_DATA code it fails ( ERROR_ACCESS_DENIED ). What is the problem? Run as admin. STORAGE_DEVICE_NUMBER sdn; DeviceIoControl(hDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &cbReaded, NULL); SENDCMDINPARAMS scip; scip.cBufferSize = READ_ATTRIBUTE_BUFFER_SIZE; scip.irDriveRegs.bFeaturesReg = READ_ATTRIBUTES; scip.irDriveRegs.bSectorCountReg = 1; scip.irDriveRegs.bSectorNumberReg = 1; scip.irDriveRegs.bCylLowReg = SMART_CYL

Converting a drive letter to a Partition ID / Disk ID

拟墨画扇 提交于 2020-02-22 06:58:25
问题 Given a drive letter, how do I get the OSImage InstallTo Partition ID and Disk ID without using the registry? 回答1: The WMI class Win32_DiskPartition is what I need. Now to figure out how to use WMI to get this information from a drive letter. Win32_LogicalDisk is also useful, MSDN Example, and this stackoverflow answer. Update: Hmm, this doesn't work! Not in the Windows Installer anyway (WMI is missing from Windows PE!!) so I am using the other answer QueryDosDevice (e.g. \\.\PhysicalDisk1

应用程序与驱动程序通信 DeviceIoControl

人走茶凉 提交于 2020-01-19 19:27:26
本文为转载,参考链接地址 https://blog.csdn.net/li_wen01/article/details/80137566 https://www.cnblogs.com/lsh123/p/7354573.html DeviceIoControl 将控制代码直接发送到指定的设备驱动程序,使相应的设备执行相应的操作。 这种通信方式,就是驱动程序和应用程序自定义一种IO控制码,然后调用DeviceIoControl函数,IO管理器会产生一个MajorFunction 为IRP_MJ_DEVICE_CONTROL(DeviceIoControl函数会产生此IRP),MinorFunction 为自己定义的控制码的IRP,系统就调用相应的处理IRP_MJ_DEVICE_CONTROL的派遣函数,你在派遣函数中判断MinorFunction ,是自定义的控制码你就进行相应的处理。 BOOL DeviceIoControl( HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped );

HDD serial number flipped every 2 bytes in Windows XP, Vista and 7 but not in Windows 8

荒凉一梦 提交于 2020-01-01 08:26:08
问题 I need to get HDD serial number to use it as a key for licensing a software. I used diskid32 code in this url: http://www.winsim.com/diskid32/diskid32.html It used the DeviceIoControl Win32 API with the IO control code of IOCTL_STORAGE_QUERY_PROPERTY . It worked. However, when I double check with the actual serial number printed on the HDD itself, I found that every 2 bytes of the number was flipped. A simple solution could be to simply flip the bytes back. It worked in Windows XP, Vista and

DeviceIoControl does not set output buffer

一曲冷凌霜 提交于 2019-12-24 04:13:07
问题 I'm having some problems with DeviceIOControl . I'm trying to read the disk geometry from a physical drive but the output buffer is never set. Here is a sample of my code, a simple function that is supposed to get the disk geometry and return whether the disk is removable: public static bool IsDeviceRemovable(int DriveNo) { string Filename=@"\\.\Physicaldrive"+DriveNo; SafeFileHandle drive=CreateFile( Filename, FileAccess_e.None, FileShare_e.Write|FileShare_e.Read, IntPtr.Zero,

How to disconnect a bluetooth device from C# .Net in Win7

强颜欢笑 提交于 2019-12-22 01:15:55
问题 I would like to disconnect a bluetooth device from my c# .Net application, that runs on Win 7 x64. I Know that MS provides very little functionnality reguarding BT on .Net. I've searched 32feet.Net, and found how to connect, discover, get information, ... but nothing about disconnecting (Have I missed something ?). Then, I found on Msdn IOCTL_BTH_DISCONNECT_DEVICE. The problem is that I can't understand how to call it. It Seems that I shoud use DeviceIOControl with Platform Invoke, but I'm

应用程序与驱动程序交互函数DeviceIoControl详解

人盡茶涼 提交于 2019-12-21 03:32:50
这种通信方式,就是驱动程序和应用程序自定义一种IO控制码,然后调用DeviceIoControl函数,IO管理器会产生一个MajorFunction 为IRP_MJ_DEVICE_CONTROL(DeviceIoControl函数会产生此IRP),MinorFunction 为自己定义的控制码的IRP,系统就调用相应的处理IRP_MJ_DEVICE_CONTROL的派遣函数,你在派遣函数中判断MinorFunction ,是自定义的控制码你就进行相应的处理。 一.先谈一下这个定义IO控制码 ,其实可以看作是一种通信协议。 看看CTL_CODE原型:    # define CTL_CODE( DeviceType, Function, Method, Access ) ( \   ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \   ) 可以看到,这个宏四个参数,自然是一个32位分成了4部分,高16位存储设备类型,14~15位访问权限,2~13位操作功能,最后0,1两位就是确定缓冲区是如何与I/O和文件系统数据缓冲区进行数据传递方式,最常见的就是METHOD_BUFFERED。 自定义CTL_CODE: #define IOCTL_Device_Function CTL_CODE