NoUsbWarning

Get rid of the annoying "Do you want to scan and fix ..." question

Theory

Question to scan removable drive

After porting to Windows Vista, loads of users see the annoying question "Do you want to scan and fix Removable Disk (E:)?" when inserting removable drive. When the user inserts a removable drive to an USB slot, Explorer calls function FSCTL_IS_VOLUME_DIRTY to check if the removable drive was ejected properly. However, even if yes, the question still shows.

Solution

When looking for solution, I hadn't found any legal solution how to get rid of the question. It depends on removable device driver, which is part of Windows. So I solved the problem by less graceful way, which was hooking of NtFsControlFile in the import table of Kernel32.dll (Kernelbase.dll in Windows 7):

static NTSTATUS NTAPI MyNtFsControlFile(      
    IN  HANDLE FileHandle,
    IN  HANDLE Event,
    IN  PIO_APC_ROUTINE ApcRoutine,
    IN  PVOID ApcContext,
    OUT PIO_STATUS_BLOCK IoStatusBlock,
    IN  ULONG FsControlCode,
    IN  PVOID InputBuffer,
    IN  ULONG InputBufferLength,
    IN  PVOID OutputBuffer,
    IN  ULONG OutputBufferLength)
{
    NTSTATUS Status;
    LPDWORD pdwPatchValue;

    Status = NtFsControlFile(FileHandle,
                             Event,
                             ApcRoutine,
                             ApcContext,
                             IoStatusBlock,
                             FsControlCode,
                             InputBuffer,
                             InputBufferLength,
                             OutputBuffer,
                             OutputBufferLength);

    // If the IOCTL was FSCTL_IS_VOLUME_DIRTY, we pretend it's NOT dirty
    if(Status == STATUS_SUCCESS && FsControlCode == FSCTL_IS_VOLUME_DIRTY)
    {
        if(OutputBufferLength <= 4)
        {
            pdwPatchValue = (LPDWORD)OutputBuffer;
            pdwPatchValue[0] = 0;
        }
    }

    return Status;
}

The hook code simply checks if it's query for the dirty flag, and if yes, it pretends that the media has been removed properly. The result is that the user will never see the question.

Installation

Download the ZIP file shown below, unzip it and choose 32-bit or 64-bit DLL, depending on your operating system version. Copy it to the Windows\System32 directory and run the following command on the command line:

RegSvr32.exe C:\Windows\System32\NoUsbWarning.dll

The DLL gets registered and after every logon, it gets loaded to Explorer.exe. You will not see the above mentioned question again, unless you unregister it or you restart Explorer.exe. You can unregister the DLL using:

RegSvr32.exe /u C:\Windows\System32\NoUsbWarning.dll

Download