'commit'
This commit is contained in:
@@ -121,6 +121,102 @@ namespace WpsInstaller
|
||||
Pause();
|
||||
}
|
||||
|
||||
static void UninstallOldVersions()
|
||||
{
|
||||
Console.WriteLine("Checking for existing versions to uninstall...");
|
||||
|
||||
// 1. Cleanup VSTO Keys
|
||||
CleanupVstoKeys();
|
||||
|
||||
// 2. Cleanup WPS Keys
|
||||
CleanupWpsKeys();
|
||||
|
||||
// 3. Cleanup COM Registration (WPS)
|
||||
UnregisterCom("{D8E52004-9D68-4509-8A11-66774D4F0523}", "WordAddIn.WpsAddIn");
|
||||
}
|
||||
|
||||
static void UnregisterCom(string guid, string progId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try to find CodeBase from HKCR\CLSID\{GUID}\InprocServer32
|
||||
string clsidKeyPath = @"CLSID\" + guid;
|
||||
string inprocKeyPath = clsidKeyPath + @"\InprocServer32";
|
||||
string oldDllPath = null;
|
||||
|
||||
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(inprocKeyPath))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
oldDllPath = key.GetValue("CodeBase") as string;
|
||||
if (string.IsNullOrEmpty(oldDllPath))
|
||||
{
|
||||
oldDllPath = key.GetValue("") as string; // Default value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(oldDllPath))
|
||||
{
|
||||
// Fix file:/// prefix if present
|
||||
if (oldDllPath.StartsWith("file:///", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
oldDllPath = oldDllPath.Substring(8).Replace('/', '\\');
|
||||
}
|
||||
|
||||
if (File.Exists(oldDllPath))
|
||||
{
|
||||
Console.WriteLine(" Found old COM registration pointing to: " + oldDllPath);
|
||||
Console.WriteLine(" Unregistering assembly...");
|
||||
|
||||
string regAsmPath = GetRegAsmPath();
|
||||
if (!string.IsNullOrEmpty(regAsmPath))
|
||||
{
|
||||
string args = string.Format("\"{0}\" /u /tlb", oldDllPath);
|
||||
ProcessStartInfo psi = new ProcessStartInfo(regAsmPath, args);
|
||||
psi.UseShellExecute = false;
|
||||
psi.RedirectStandardOutput = true;
|
||||
psi.CreateNoWindow = true;
|
||||
|
||||
using (Process p = Process.Start(psi))
|
||||
{
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
// Console.WriteLine(output); // Optional: show output
|
||||
}
|
||||
Console.WriteLine(" [OK] RegAsm /u completed.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(" Old COM DLL not found at: " + oldDllPath + ". Skipping RegAsm /u.");
|
||||
}
|
||||
}
|
||||
|
||||
// Force delete registry keys to be sure
|
||||
try
|
||||
{
|
||||
Registry.ClassesRoot.DeleteSubKeyTree(clsidKeyPath, false);
|
||||
Console.WriteLine(" [OK] Deleted HKCR\\" + clsidKeyPath);
|
||||
}
|
||||
catch {}
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(progId))
|
||||
{
|
||||
Registry.ClassesRoot.DeleteSubKeyTree(progId, false);
|
||||
Console.WriteLine(" [OK] Deleted HKCR\\" + progId);
|
||||
}
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(" Warning during COM unregistration: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
static void Pause()
|
||||
{
|
||||
Console.WriteLine("\nPress any key to exit...");
|
||||
|
||||
Reference in New Issue
Block a user