105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Runtime.InteropServices;
|
||
using System.Security.Principal;
|
||
using System.Windows.Forms;
|
||
|
||
namespace LDUninstaller.Launcher
|
||
{
|
||
internal static class Program
|
||
{
|
||
[DllImport("shell32.dll", SetLastError = true)]
|
||
private static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
|
||
|
||
[STAThread]
|
||
static void Main(string[] args)
|
||
{
|
||
try { SetCurrentProcessExplicitAppUserModelID("LDSoftware.LDUninstaller"); } catch { }
|
||
|
||
ApplicationConfiguration.Initialize();
|
||
|
||
// 1. Architecture check
|
||
var arch = RuntimeInformation.OSArchitecture;
|
||
|
||
// 2. Administrator check
|
||
if (!IsAdministrator())
|
||
{
|
||
try
|
||
{
|
||
string exePath = Process.GetCurrentProcess().MainModule?.FileName ?? Application.ExecutablePath;
|
||
var psi = new ProcessStartInfo
|
||
{
|
||
FileName = exePath,
|
||
Arguments = BuildArgumentString(args),
|
||
UseShellExecute = true,
|
||
Verb = "runas"
|
||
};
|
||
Process.Start(psi);
|
||
return;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
MessageBox.Show(
|
||
"Bu uygulamanın tüm yazılımları eksiksiz tespit edebilmesi ve kalıntıları temizleyebilmesi için Yönetici (Administrator) yetkilerine ihtiyacı vardır.",
|
||
"Yönetici İzni Gerekli - LD Uninstaller",
|
||
MessageBoxButtons.OK,
|
||
MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 3. Locate LDUninstaller.UI.exe
|
||
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||
string uiPath = Path.Combine(baseDir, "LDUninstaller.UI.exe");
|
||
|
||
if (!File.Exists(uiPath))
|
||
{
|
||
// In Debug / Development environment check
|
||
string siblingUi = Path.GetFullPath(Path.Combine(baseDir, "..", "LDUninstaller.UI", "LDUninstaller.UI.exe"));
|
||
if (File.Exists(siblingUi))
|
||
{
|
||
uiPath = siblingUi;
|
||
}
|
||
}
|
||
|
||
if (File.Exists(uiPath))
|
||
{
|
||
var psi = new ProcessStartInfo
|
||
{
|
||
FileName = uiPath,
|
||
Arguments = BuildArgumentString(args),
|
||
UseShellExecute = false,
|
||
WorkingDirectory = Path.GetDirectoryName(uiPath)
|
||
};
|
||
Process.Start(psi);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show(
|
||
$"Ana arayüz yürütülebilir dosyası bulunamadı:\n{uiPath}",
|
||
"Başlatma Hatası",
|
||
MessageBoxButtons.OK,
|
||
MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
|
||
private static bool IsAdministrator()
|
||
{
|
||
using var identity = WindowsIdentity.GetCurrent();
|
||
var principal = new WindowsPrincipal(identity);
|
||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||
}
|
||
|
||
private static string BuildArgumentString(string[] args)
|
||
{
|
||
if (args == null || args.Length == 0) return string.Empty;
|
||
return string.Join(" ", args.Select(a =>
|
||
{
|
||
if (string.IsNullOrEmpty(a)) return "\"\"";
|
||
if (a.Contains(" ") && !a.StartsWith("\"")) return $"\"{a}\"";
|
||
return a;
|
||
}));
|
||
}
|
||
}
|
||
}
|