Menu

#17 Disable "There is no disk in the drive..." Popup

0.8
closed
nobody
None
2018-11-02
2017-06-29
Michael
No

When I start up the program I get a "There is no disk in the drive. Please insert a disk into drive "X"" Popup for every slot in my card reader that has no card in it.
I already did some research on how to disable the popup. It is caused by the CreateFile call in the kernel32.dll. You can disable it if you call the SetErrorMode in kernel32.dll with the SEM_FAILCRITICALERRORS option. Would be nice if you could include this into the official code. Here is a diff file that fixes the error message on startup:

 dotNetDiskImager/DiskAccess/NativeDiskWrapper.cs | 11 ++++++++++-
 dotNetDiskImager/Models/Utils.cs                 | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/dotNetDiskImager/DiskAccess/NativeDiskWrapper.cs b/dotNetDiskImager/DiskAccess/NativeDiskWrapper.cs
index 640a102..9fc7bd8 100644
--- a/dotNetDiskImager/DiskAccess/NativeDiskWrapper.cs
+++ b/dotNetDiskImager/DiskAccess/NativeDiskWrapper.cs
@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using dotNetDiskImager.Models;

 namespace dotNetDiskImager.DiskAccess
 {
@@ -431,7 +432,15 @@ namespace dotNetDiskImager.DiskAccess
                             else
                             {
                                 NativeDisk.CloseHandle(handle);
-                                handle = NativeDisk.CreateFile(name, NativeDisk.FILE_READ_DATA, NativeDisk.FILE_SHARE_READ | NativeDisk.FILE_SHARE_WRITE, IntPtr.Zero, NativeDisk.OPEN_EXISTING, 0, IntPtr.Zero);
+                                Utils.SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS);
+                                try
+                                {
+                                    handle = NativeDisk.CreateFile(name, NativeDisk.FILE_READ_DATA, NativeDisk.FILE_SHARE_READ | NativeDisk.FILE_SHARE_WRITE, IntPtr.Zero, NativeDisk.OPEN_EXISTING, 0, IntPtr.Zero);
+                                }
+                                finally
+                                {
+                                    Utils.SetErrorMode(ErrorModes.SYSTEM_DEFAULT);
+                                }

                                 if (handle == NativeDisk.INVALID_HANDLE_VALUE)
                                 {
diff --git a/dotNetDiskImager/Models/Utils.cs b/dotNetDiskImager/Models/Utils.cs
index 1fe8ddb..a50e683 100644
--- a/dotNetDiskImager/Models/Utils.cs
+++ b/dotNetDiskImager/Models/Utils.cs
@@ -8,9 +8,23 @@ using System.Threading.Tasks;

 namespace dotNetDiskImager.Models
 {
+    [Flags]
+    public enum ErrorModes : uint
+    {
+        SYSTEM_DEFAULT = 0x0,
+        SEM_FAILCRITICALERRORS = 0x0001,
+        SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
+        SEM_NOGPFAULTERRORBOX = 0x0002,
+        SEM_NOOPENFILEERRORBOX = 0x8000
+    }
+
     public class Utils
     {
         [DllImport("kernel32.dll")]
+        public static extern ErrorModes SetErrorMode(ErrorModes uMode);
+
+
+        [DllImport("kernel32.dll")]
         static extern uint SetThreadExecutionState(uint esFlags);
         const uint ES_CONTINUOUS = 0x80000000;
         const uint ES_SYSTEM_REQUIRED = 0x00000001;

Discussion

  • Filip Sikora

    Filip Sikora - 2017-06-29

    Thank you very much for your effort. Will add this to the next release.

     
  • Filip Sikora

    Filip Sikora - 2018-11-02
    • status: open --> closed
     
  • Filip Sikora

    Filip Sikora - 2018-11-02

    Done, closing.

     

Log in to post a comment.

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.