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

  • SEARCH
  • Home
  • 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 7641017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:49:01+00:00 2026-05-31T08:49:01+00:00

I need to disable cdrom and the usb mass storage drivers using c# windows

  • 0

I need to disable cdrom and the usb mass storage drivers using c# windows service. i have noticed there is a post Disable the use of CD drive (VB.NET) but it keeps ejecting the cdrom tray. does anyone know how to disable the cd rom other than using this method.????

  • 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-05-31T08:49:02+00:00Added an answer on May 31, 2026 at 8:49 am

    I Have fund a solution

    #region EjectMedia
            const uint GENERICREAD = 0x80000000;
            const uint OPENEXISTING = 3;
            const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;
            const int INVALID_HANDLE = -1;
    
            private static IntPtr fileHandle;
            private static uint returnedBytes;
    
            [DllImport("kernel32", SetLastError = true)]
            static extern IntPtr CreateFile(string fileName,
            uint desiredAccess,
            uint shareMode,
            IntPtr attributes,
            uint creationDisposition,
            uint flagsAndAttributes,
            IntPtr templateFile);
            [DllImport("kernel32", SetLastError = true)]
            static extern int CloseHandle(IntPtr driveHandle);
            [DllImport("kernel32", SetLastError = true)]
            static extern bool DeviceIoControl(IntPtr driveHandle,
            uint IoControlCode,
            IntPtr lpInBuffer,
            uint inBufferSize,
            IntPtr lpOutBuffer,
            uint outBufferSize,
            ref uint lpBytesReturned,
                     IntPtr lpOverlapped);
            #endregion
    
    private void loop(object sender, EventArgs e)
    {
     DriveInfo[] allDrives = DriveInfo.GetDrives();
                foreach (DriveInfo d in allDrives)
                {
                    if (d.IsReady)
                    {
                        if (d.DriveType == DriveType.Removable || d.DriveType == DriveType.Ram || d.DriveType == DriveType.Unknown) 
                            Eject(@"\\.\" + d.Name.Substring(0, 1) + ":");
                    }
                }
    }
    
     public void Eject(string driveLetter)
            {
                try
                {
                    fileHandle = CreateFile(driveLetter, GENERICREAD, 0, IntPtr.Zero, OPENEXISTING, 0, IntPtr.Zero);
                    if ((int)fileHandle != INVALID_HANDLE)
                        DeviceIoControl(fileHandle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, ref returnedBytes, IntPtr.Zero);
                }
    
                catch
                {
                    EventLog.WriteEntry(Marshal.GetLastWin32Error().ToString());
                }
    
                finally
                {
                    CloseHandle(fileHandle);
                    fileHandle = IntPtr.Zero;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to disable slickgrid horizontal scrollbar. I have only one column and have
OK, I have two HTML select elements and a button. I need to disable
Need to disable already selected options in select box using jQuery. I'd like it
I need to disable an image which I am using in <a "href"> until
i need to disable the arrow keys in a flowplayer.org scrollable i have a
I need to disable the Mouse Clicks, Mouse movement for a specific windows for
I have some HTML text inputs into a WebView, and I need to disable
I have an ajax controltoolkit reorderlist within an asp.net application. I need to disable
I need to disable changing focus with arrows on form. Is there an easy
I need to disable the multimedia contents in IE Programatically. Is there any way

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.