Questions tagged [deviceiocontrol]

The DeviceIoControl function provides a device input and output control (IOCTL) interface through which an application can communicate directly with a device driver.

The DeviceIoControl function provides a device input and output control (IOCTL) interface through which an application can communicate directly with a device driver. The DeviceIoControl function is a general-purpose interface that can send control codes to a variety of devices. Each control code represents an operation for the driver to perform. For example, a control code can ask a device driver to return information about the corresponding device, or direct the driver to carry out an action on the device, such as formatting a disk.

A number of standard control codes are defined in the SDK header files. In addition, device drivers can define their own device-specific control codes. For a list of standard control codes included in the SDK documentation, see the Remarks section of DeviceIoControl.

The types of control codes you can specify depend on the device being accessed and the platform on which your application is running. Applications can use the standard control codes or device-specific control codes to perform direct input and output operations on a floppy disk drive, hard disk drive, tape drive, or CD-ROM drive.

115 questions
18
votes
4 answers

In .NET, how do I Create a Junction in NTFS, as opposed to a Symlink?

I'm trying to create an NTFS Junction. From the cmd line I can do this using the junction.exe tool from sysinternals. The output of a DIR cmd for a junction looks like this: Volume in drive C has no label. Volume Serial Number is C8BC-2EBD …
Cheeso
  • 189,189
  • 101
  • 473
  • 713
15
votes
5 answers

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

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…
A.Danesh
  • 844
  • 11
  • 40
13
votes
1 answer

Pinvoke DeviceIoControl parameters

I'm working on a C# project using DeviceIoControl. I've consulted the related Pinvoke.net page for my signature: [DllImport("Kernel32.dll", SetLastError = false, CharSet = CharSet.Auto)] public static extern bool DeviceIoControl( SafeFileHandle…
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
10
votes
2 answers

Trouble passing a C# string from userland to kernelmode C and using it to find specific LDR_DATA_TABLE_ENTRY

I am having difficulty comparing a string passed from usermode type LPWSTR to a LDR table entry type UNICODE_STRING Kernel C: struct { int pid; int user_pid; int size; int protection_mode; int allocation_type; void* address; …
Ben
  • 749
  • 1
  • 7
  • 18
9
votes
5 answers

C# WriteFile() Stops Writing at Sector 242 on USB Drives

I wrote the below code to write 0xFF to all bytes on my USB storeage device. For some reason the WriteFile() calls begin to error out at sector 242. I have done this on two separate USB storage devices and then examined the devices in a hex…
Brandon Stout
  • 359
  • 10
  • 22
7
votes
2 answers

Physical disk size not correct (IoCtlDiskGetDriveGeometry)

I use the code below to get the physical disk size, but the size returned is not correct. I've checked the size with other tools. The code below reports Total disk space: 8.249.955.840 bytes and it should be Total disk space: 8.254.390.272…
John Doe
  • 9,843
  • 13
  • 42
  • 73
7
votes
2 answers

How to correctly retrieve battery serial number?

In Delphi 7 I'm working on a library implementing an object encapsulating information about the batteries attached to a system. It's working well, except for retrieving the serial number for the battery. The code I am using for this call is as…
Restless
  • 176
  • 1
  • 7
6
votes
4 answers

Take disks online/offline

I have a program that is doing raw IO to disks within Windows. All works fine if the target disk is online. However, the default behavior in some Windows OSes is to have new disks initially offline. I am having a hard time finding the correct API…
Joe
  • 41,484
  • 20
  • 104
  • 125
6
votes
2 answers

How to call DeviceIOControl code asynchronously?

I am trying to call DeviceIO functions asynchronously by using the OVERLAPPED structure as described on MSDN. I am using the FSCTL_ENUM_USN_DATA control code to enumerate the MFT of NTFS drives but i am not able to run it asynchronously. The file…
6
votes
1 answer

Why raw disk read in C# reads from slightly shifted offset?

I'm trying to read raw disk. I've successfully opened the drive and obtained valid handle (CreateFile), set offset for that handle to zero (SetFilePointerEx) and read the data to a buffer Byte[] (ReadFile). So far so good. But for some unknown…
SmartK8
  • 2,616
  • 1
  • 29
  • 37
5
votes
3 answers

Walking the NTFS Change Journal on Windows 10

I'm trying to read the NTFS Change Journal but I've noticed that all the example code I can find fails on Windows 10, even though it works on Windows 7. For example, Microsofts own example Walking a Buffer of Change Journal Records works on Windows…
BenS1
  • 183
  • 2
  • 11
5
votes
1 answer

Getting a Folder ID C#

I am trying to track a files and folders through their lifetime (they may be moved or renamed). I have done searching and found that FileSystemWatcher might be the most popular way to track files and folders, however, this will not work for me as…
Matt
  • 61
  • 1
  • 6
4
votes
1 answer

Can't Get Reparse Point Information for the OneDrive Folder

I'm using the code below to retrieve reparse point information in my application. This works great for symbolic links and junctions, but fails with 'Not a reparse point' for the OneDrive folder and all it's child items. using (SafeFileHandle…
Randall Deetz
  • 512
  • 4
  • 25
4
votes
1 answer

Creating multiple partitions on USB using C#

Iam trying to use DeviceIOControl to create multiple partiions in USB. It is always creating only one partition. Here is my source code [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr CreateFile(string lpFileName, uint…
md.jamal
  • 4,067
  • 8
  • 45
  • 108
3
votes
2 answers

Converting a drive letter to a Partition ID / Disk ID

Given a drive letter, how do I get the OSImage InstallTo Partition ID and Disk ID without using the registry?
unixman83
  • 9,421
  • 10
  • 68
  • 102
1
2 3 4 5 6 7 8