//get Access to file and folder private void button1_Click(object sender, EventArgs e) { Hide(); var Lb = new LoadBar(); Lb.ShowDialog(); string deletePath1 = Path.GetTempPath(); //string deletePath2 = @"C:\Windows\Prefetch"; //Temp Delete var di = new DirectoryInfo(deletePath1); //var di2 = new DirectoryInfo(deletePath2); foreach (var file in di.EnumerateFileSystemInfos()) { try { file.Delete(); if (file.Attributes == FileAttributes.Directory) { countFolders++; } else { countFiles++; } } catch { textBox2.Text += "\r\nTemp File or Folder is Using..."; } } //Prefetch Delete //bool a = false; //try //{ // Directory.GetAccessControl(deletePath2); // DirectorySecurity ds = new DirectorySecurity(deletePath2, AccessControlSections.Access); // Directory.SetAccessControl(deletePath2, ds); // WindowsIdentity wi = WindowsIdentity.GetCurrent(); // string user = wi.Name; // AddFileSecurity(deletePath2, @user, // FileSystemRights.FullControl, AccessControlType.Allow); // a = true; //} //catch (Exception ex) //{ // MessageBox.Show(ex.ToString()); //} //if (a) //{ // foreach (var file in Directory.GetFiles(deletePath2)) // { // try // { // File.SetAttributes(file, FileAttributes.Normal); // File.Delete(file); // countFiles++; // } // catch // { // textBox2.Text += "\r\nPrefetch File is Using..."; // } // } //} //Process.Start(@"C:\Users\davom\Desktop\Building project (OPTIMTOOL)\WindowsFormApp1\WindowsFormsApp1\bin\bats\PrefetchDelete.bat"); Lb.Close(); SystemSounds.Beep.Play(); new succ().ShowDialog(); Show(); textBox2.Text += $"\r\nFile Deleted: {countFiles} \r\nFolder Deleted: {countFolders}"; countFiles = 0; countFolders = 0; }
////High Performance private void button2_Click(object sender, EventArgs e) { Hide(); var Lb = new LoadBar(); Lb.ShowDialog(); // if (checkBox1.Checked) // { // foreach (var Proc in Process.GetProcesses()) // { // if (processList.PList.Count > 0) // { // for (int i = 0; i < processList.PList.Count; i++) // { // if (Proc.ProcessName.Equals(processList.PList[i])) // { // try // { // Proc.Kill(); // countProcess++; // } // catch // { // textBox2.Text += "\r\nAccess denied!"; // } // } // } // } // } // } // else // { // foreach (Process Proc in Process.GetProcesses()) // { // bool isDefault = false; // foreach (var proc1 in processList.defProcList) // { // if (Proc.ProcessName.Equals(proc1)) // { // isDefault = true; // } // } // if (!isDefault) // { // try // { // Proc.Kill(); // countProcess++; // } // catch // { // textBox2.Text += "\r\nAccess denied!"; // } // } // } // } Lb.Close(); SystemSounds.Beep.Play(); new succ().ShowDialog(); Show(); textBox2.Text += $"\r\nProcess Killed : {countProcess}"; }