This may help you
pseudocode+sample
Hiding:
Skip steps 1&2 if you know the drive letter
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.