Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:17+00:00 2026-06-13T05:08:17+00:00

I am trying to identify a device using ATA_PASS_THROUGH_EX. When I see the output

  • 0

I am trying to identify a device using ATA_PASS_THROUGH_EX.

When I see the output buffer, it has all invalid data. Can someone help me what I am doing wrong?

#include <Windows.h>
#include <ntddscsi.h>
#include <iostream>

void main() {
    WCHAR *fileName = (WCHAR * ) "\\.\PhysicalDrive0";
    HANDLE handle = CreateFile(
       fileName, 
       GENERIC_READ | GENERIC_WRITE, //IOCTL_ATA_PASS_THROUGH requires read-write
       FILE_SHARE_READ, 
       NULL,            //no security attributes
       OPEN_EXISTING,
       0,              //flags and attributes
       NULL             //no template file
    );


    ATA_PASS_THROUGH_EX inputBuffer;
    inputBuffer.Length = sizeof(ATA_PASS_THROUGH_EX);
    inputBuffer.AtaFlags = ATA_FLAGS_DATA_IN;
    inputBuffer.DataTransferLength = 0;
    inputBuffer.DataBufferOffset = 0;

    IDEREGS *ir  = (IDEREGS *) inputBuffer.CurrentTaskFile;
    ir->bCommandReg = 0xEC; //identify device
    ir->bSectorCountReg = 1;

    unsigned int inputBufferSize = sizeof(ATA_PASS_THROUGH_EX);

    UINT8 outputBuffer[512];
    UINT32 outputBufferSize = 512;
    LPDWORD bytesReturned = 0;

    DeviceIoControl( handle, IOCTL_ATA_PASS_THROUGH_DIRECT, &inputBuffer,    inputBufferSize, &outputBuffer, outputBufferSize, bytesReturned, NULL);

    DWORD error = GetLastError();

    std::cout << outputBuffer << std::endl;
    system("pause");
}

update:
When I check the error value, it is 5, which means it is an access violation. I am running in admin mode. Am I doing something wrong?

-Nick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:08:18+00:00Added an answer on June 13, 2026 at 5:08 am

    I’ve done this using code that looks like this:

    int foo()
    {
        int iRet( 0 );
    
        // Open handle to disk.
        HANDLE hDevice( ::CreateFileW( L"\\\\.\\PhysicalDrive0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ) );
        if( hDevice == INVALID_HANDLE_VALUE )
        {
            std::wcout << L"CreateFileW( " << sPath << L" ) failed.  LastError: " << GetLastError() << std::endl;
            return -1;
        }
    
        //
        // Use IOCTL_ATA_PASS_THROUGH
        //
        std::vector< UCHAR > vBuffer( sizeof( ATA_PASS_THROUGH_EX ) + sizeof( IDENTIFY_DEVICE_DATA ), 0 );
        PATA_PASS_THROUGH_EX pATARequest( reinterpret_cast< PATA_PASS_THROUGH_EX >( &vBuffer[0] ) );
        pATARequest->AtaFlags = ATA_FLAGS_DATA_IN | ATA_FLAGS_DRDY_REQUIRED;
        pATARequest->Length = sizeof( ATA_PASS_THROUGH_EX );
        pATARequest->DataBufferOffset = sizeof( ATA_PASS_THROUGH_EX );
        pATARequest->DataTransferLength = sizeof( IDENTIFY_DEVICE_DATA );
        pATARequest->TimeOutValue = 2;
        pATARequest->CurrentTaskFile[6] = ID_CMD;
    
        ULONG ulBytesRead;
        if( DeviceIoControl( hDevice, IOCTL_ATA_PASS_THROUGH, 
            &vBuffer[0], ULONG( vBuffer.size() ),
            &vBuffer[0], ULONG( vBuffer.size() ),
            &ulBytesRead, NULL ) == FALSE )
        {
            std::cout << "DeviceIoControl(IOCTL_ATA_PASS_THROUGH) failed.  LastError: " << GetLastError() << std::endl;
            iRet = -1;
        }
        else
        {
            // Fetch identity blob from output buffer.
            PIDENTIFY_DEVICE_DATA pIdentityBlob( reinterpret_cast< PIDENTIFY_DEVICE_DATA >( &vBuffer[ sizeof( ATA_PASS_THROUGH_EX ) ] ) );
        }
    
        CloseHandle( hDevice );
    
        return iRet;
    }
    

    Note that this must be run from an administrator account or elevated context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has redundant data and I'm trying to identify all
I am trying to identify when an action without authorization has been made. Is
I am trying to identify duplicate serial numbers from the following xml using XPath
I am trying to identify all the nodes in a tree that lead to
Using Delphi XE 2 I've trying to identify the zoom direction to apply the
i am trying to identify the workstations in my network using c#, what are
I am trying to identify a method for obtaining nearby wifi access points using
All, I am trying to identify plain text files with Mac line endings and,
I am trying to identify all the <UL> that contain a menu list by
We are trying to find a way to identify specific purchases when using Google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.