You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.3 KiB

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace TJprojMain_remover
{
public class Utils
{
private const int SM_CLEANBOOT = 67;
[DllImport("user32.dll")]
private static extern int GetSystemMetrics(int smIndex);
public static bool IsSafeMode()
{
return GetSystemMetrics(SM_CLEANBOOT) != 0;
}
public static void RegRemoveIfExists(string key, string name)
{
using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(key, writable: true))
{
if (regKey != null)
{
if (regKey.GetValue(name) != null)
{
regKey.DeleteValue(name);
Log.Critical($"Registry key {name} found and removed!");
}
else
{
Log.Error($"Registry key {name} not found!");
}
}
}
}
public static void Unhide(string path)
{
Process.Start("attrib", $"-r -a -s -h \"{path}\"");
}
public static void FRemoveIfExists(string path, bool processCheck = false)
{
try
{
if (File.Exists(path))
{
if (processCheck)
{
try
{
var processes = Process.GetProcessesByName(new FileInfo(path).Name);
processes.Where(x => new FileInfo(x.MainModule.FileName).FullName == new FileInfo(path).FullName).FirstOrDefault().Kill();
}
catch { }
}
File.Delete(path);
Log.Critical($"Removed {path} successfully!");
}
else
{
Log.Error($"File {path} not found!");
}
}catch(Exception ex)
{
Log.Error($"Could not delete file {path}: {ex.Message}");
}
}
}
}