دوست عزیز کلا کدهاتونو تغییر دادم اینم برنامه شما
http://www.w3-farsi.com
اولا برای فرمت میبایستی لیست درایوها رو بدست بیاری
DriveInfo[] dinfo = DriveInfo.GetDrives();
foreach (DriveInfo di in dinfo)
{
if (di.IsReady == true)
{
if (comboBox1.Text == di.Name.Remove(2))
{
label8.Text = "Drive Name:\t " + di.VolumeLabel;
label7.Text = "Size " + di.TotalSize / (1024 * 1024) + "MB\nDrive Format :" +
di.DriveFormat + "\nFree space\t" + di.AvailableFreeSpace / (1024 * 1024) + "MB\n Drive Type:\t" + di.DriveType;
}
}
}
و بعد هم برای قفل کردن پورتهای usb میتونستی از api استفاده کنی رستری این مشکلات رو داره
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"system\currentControlSet\Control\StorageDevicePolicies", true);
if (key == null)
{
Registry.LocalMachine.CreateSubKey(@"system\currentControlSet\Control\StorageDevicePolicies",
RegistryKeyPermissionCheck.ReadWriteSubTree);
key = Registry.LocalMachine.OpenSubKey(@"system\currentControlSet\Control\StorageDevicePolicies", true);
key.SetValue("WriteProtect", 1, RegistryValueKind.DWord);
}
else if (key.GetValue("WriteProtect") != (object)(1))
{
key.SetValue("WriteProtect", 1, RegistryValueKind.DWord);
}
MessageBox.Show("ok Write protect");
اینم متد فرمت
public void format(string type, string filesystem, string labeldisk, string name)
{
DialogResult result = MessageBox.Show("", MessageBoxIcon.Question.ToString(),
MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
StreamWriter sw = File.CreateText("frmt.bat");
sw.Write("format /y" + "" + "/fs:" + filesystem + " " + name + "/v:" + labeldisk + " " + type);
sw.Close();
}
Process Oprocess = new Process();
Oprocess.StartInfo.FileName = @"frmt.bat";
Oprocess.StartInfo.UseShellExecute = true;
Oprocess.StartInfo.CreateNoWindow = true;
Oprocess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
Oprocess.Start();
Oprocess.WaitForExit();
File.Delete(@"frmt.bat");
MessageBox.Show("Format success!");
}