Results 1 to 2 of 2

Thread: CreateFile returns Incorrect function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    118

    CreateFile returns Incorrect function

    I get a list of physical disks with wmic diskdrive list command. There are two internal SSDs, one USB flash drive and one external SSD connected to USB-C port. CreateFile works for all of them except for external SSD, I get ERROR_INVALID_FUNCTION. When I connect the same SSD to USB port, it works as expected. What could be the problem?

    I found some suggestions to look into IRP_MJ_CREATE, but there is no info how to use in VB.NET.

    Code:
    Dim result = CreateFile("\\.\PHYSICALDRIVE2", EFileAccess.GenericRead Or EFileAccess.GenericWrite, EFileShare.Read Or EFileShare.Write, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Normal, IntPtr.Zero)
    If result.IsInvalid Then
        Console.WriteLine(New Win32Exception(Marshal.GetLastWin32Error()).Message)
    End If

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,962

    Re: CreateFile returns Incorrect function

    When it's mounted does GetDriveType return DRIVE_FIXED? If not the physical drive number isn't valid and you'd get low level access from "\\.\D:" or whatever letter it's on.

    IRP_MJ_CREATE is something handled inside drivers, you have no access to it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width