My task is to check whether data transfer through USB is blocked or not.
try
{
// Attempt to access a directory on a USB drive
Directory.GetDirectories(Directory.GetLogicalDrives()[0]);
Console.WriteLine("USB data transfer is available.");
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("USB data transfer is blocked.");
}
catch (Exception)
{
Console.WriteLine("Unable to determine USB data transfer status.");
}
I tried above using System.IO
Just want to check whether USB Data transfer is blocked or not .