Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I wants to hide the removable disk while i am pressing enter button meanwhile that hiding removable disk shows when i click another button . here am using c# window application. Invite all replies ASAP.


Thanks in Advance

Dhinesh Kumar.V
Posted
Comments
Ganesan Senthilvel 2-Jul-12 1:16am    
You can check out code at http://karlagius.com/2009/03/04/keeping-track-of-usb-devices-using-wmi/.

1 solution

This may help you
pseudocode+sample
Hiding:
Skip steps 1&2 if you know the drive letter

C#
1. Find removable drives:

foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
          {
              if (driveInfo.DriveType == DriveType.Removable )
              {
                  2. Get drive letter:
                     driveInfo.RootDirectory.FullName
               }
          }



3.Use code from here[^] to delete the drive letter(DeleteVolumeDriveLetter):(replace @"D:\"
in code example
by relevant drive letter string)
Example
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetVolumeNameForVolumeMountPoint(string
    lpszVolumeMountPoint, [Out] StringBuilder lpszVolumeName,
    uint cchBufferLength);

[DllImport("kernel32.dll")]
static extern bool DeleteVolumeMountPoint(string lpszVolumeMountPoint);

[DllImport("kernel32.dll")]
static extern bool SetVolumeMountPoint(string lpszVolumeMountPoint,
    string lpszVolumeName);

const int MAX_PATH = 260;

private void RemoveDriveLetter()
{
    StringBuilder volume = new StringBuilder(MAX_PATH);
    if (!GetVolumeNameForVolumeMountPoint(@"D:\", volume, (uint)MAX_PATH))
        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());

    if (!DeleteVolumeMountPoint(@"D:\"))
        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
    
}


Un-hiding:
1: keep the
volume
from step 3 and use it to restore "VolumeName":

private void RestoreVolumeName()
{
if (!SetVolumeMountPoint(@"D:\", volume.ToString()))
        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());

}


I have no time to explain this in more detail.
Sorry for my English.
Glad to help you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-12 3:24am    
Respect, my 5.
--SA
Sandeep Mewara 2-Jul-12 4:29am    
5! for super effort and time spent in answering it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900