-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExtensionDeleteToRecycleBin.cs
84 lines (79 loc) · 2.72 KB
/
ExtensionDeleteToRecycleBin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualBasic.FileIO;
namespace ALL_LEGIT
{
/// <summary>
/// ExtensionDeleteToRecycleBin.cs
/// </summary>
public static class ExtensionDeleteToRecycleBin
{
public static Dictionary<string, string> DeleteDict = new Dictionary<string, string>();
/// <summary>
/// Delete File To Recycle Bin
/// WARMING: NETWORK FILES DON'T GO TO RECYCLE BIN
/// </summary>
/// <param name="file"></param>
public static void FileRecycle(this string file)
{
try
{
if (File.Exists(file))
{
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file,
Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin, UICancelOption.DoNothing);
}
}
catch
{
File.Delete(file);
}
}
/// <summary>
/// Delete Path To Recycle Bin
/// WARMING: NETWORK PATHS DON'T GO TO RECYCLE BIN
/// </summary>
/// <param name="path"></param>
public static void DirectoryRecycle(this string path)
{
try
{
if (Directory.Exists(path))
{
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(path,
Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin, UICancelOption.DoNothing);
}
}
catch
{
Directory.Delete(path);
}
}
public static void CmdKILL(string appname)
{
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (process.ProcessName.Contains(appname))
{
ProcessStartInfo info = new ProcessStartInfo(@"cmd.exe");
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Arguments = $"/C WMIC PROCESS WHERE \"Name Like '%{appname}%'\" CALL Terminate 1>nul 2>nul";
Process.Start(info);
}
}
}
}
}