private void clean_Load(object sender, EventArgs e) { string sysPath = Environment.GetFolderPath(Environment.SpecialFolder.System); sysDrive = Path.GetPathRoot(sysPath); SubutaiDir = AP.get_env_var("Subutai"); logger.Info("Uninstalling: date = {0}", $"{ DateTime.Now.ToString("yyyyMMddhhmm")}"); if (toLog) { logger.Info("Starting to uninstall Subutai with parameters: sysDrive: {0}; SubutaiDir: {1}; isSilent: {2}; removeAll: {3}", sysDrive, SubutaiDir, isSilent, removeAll); MessageBox.Show($"sysDrive: {sysDrive}; SubutaiDir: {SubutaiDir}; isSilent: {isSilent}; removeAll: {removeAll}; toLog: {toLog}", "OnLoad", MessageBoxButtons.OK); } if (isSilent) { runCleaning(); } }
/// <summary> /// Removes Subutai from Path environment variable /// </summary> /// <param name="str2delete">The str2delete.</param> /// <returns></returns> public static string remove_from_Path(string str2delete) { //logger.Info("Remove env"); string strPath = AP.get_env_var("Path"); //if (str2delete == "Subutai") //{ // str2delete = AP.get_env_var("Subutai"); //} if (strPath == null || strPath == "") { return("Path Empty"); } if (str2delete == null || str2delete == "") { return($"{str2delete} Empty"); } string[] strP = strPath.Split(';'); List <string> lPath = new List <string>(); foreach (string sP in strP) { if (!lPath.Contains(sP) && !sP.Contains(str2delete)) { lPath.Add(sP); } } string[] slPath = lPath.ToArray(); string newPath = string.Join(";", slPath); newPath = newPath.Replace(";;", ";"); Environment.SetEnvironmentVariable("Path", newPath, EnvironmentVariableTarget.Machine); Environment.SetEnvironmentVariable("Path", newPath, EnvironmentVariableTarget.Process); return(newPath); }
/// <summary> /// Removes the Oracle VirtualBox application. /// Problematic for now /// </summary> /// <param name="app_name">Name of the application.</param> public static void remove_app_vbox(string app_name) { string mesg = string.Format("Remove {0}? \n\nPlease do not try to remove {1} if uninstalling from Control Panel. \n\nNote: it is better to remove {2} separately.", app_name, app_name, app_name); //DialogResult drs = MessageBox.Show($"Remove {app_name}? Please, do not remove if uninstalling from Control Panel. Uninstall {app_name} separately." , $"Removing {app_name}", DialogResult drs = MessageBox.Show(mesg, $"Removing {app_name}", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (drs == DialogResult.No) { return; } string res = ""; //VirtualBox Manager, VirtualBox Interface //Stop VMs //Remove all host-only interfaces remove_host_only(); //Stop Processes/Services clean.StageReporter("", "Stopping VirtualBox processes"); Process[] vboxProcesses = Process.GetProcesses(); foreach (Process process in vboxProcesses) { if (process.ProcessName.Contains("VBox") || process.ProcessName.Contains("VirtualBox")) { MessageBox.Show($"Process: {process.ProcessName}", "Removing processes", MessageBoxButtons.OK); try { process.Kill(); Thread.Sleep(2000); } catch (Exception e) { string tmp = e.Message; } } } //Stopping services //Remove drivers C:\Windows\System32\drivers //C:\Windows\System32\drivers\VBoxDrv.sys, VBoxNetAdp6.sys, VBoxNetLwf.sys, VBoxUSBMon.sys clean.StageReporter("", "Removing VirtualBox drivers "); string dirStart = Path.Combine(clean.sysDrive, "Windows", "System32", "drivers"); string[] vbDrv = { "VBoxDrv.sys", "VBoxNetAdp6.sys", "VBoxNetLwf.sys", "VBoxUSBMon.sys" }; foreach (string drvName in vbDrv) { res = SCP.LaunchCommandLineApp("sc", $"stop {drvName.Replace(".sys","")}", true, false, 420000); string drvPath = Path.Combine(dirStart, drvName); bool b_res = FD.del_sysfile(drvPath); } clean.StageReporter("", "Removing VirtualBox directory"); dirStart = AP.get_env_var("VBOX_MSI_INSTALL_PATH"); if (dirStart == null || dirStart == "") { dirStart = Path.Combine(clean.sysDrive, "Program Files", "Oracle", "VirtualBox"); } //MessageBox.Show($"Dir: {dirStart}", "Removing Oracle Dir", MessageBoxButtons.OK); if (Directory.Exists(dirStart)) { Directory.Delete(dirStart, true); } //Clear Registry: VBoxDrv, VBoxNetAdp, VBoxUSBMon vb_clean_reg(); //Remove Env VBOX_MSI_INSTALL_PATH Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.Machine); Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.User); Environment.SetEnvironmentVariable("VBOX_MSI_INSTALL_PATH", "", EnvironmentVariableTarget.Process); clean.StageReporter("", "Removing shortcuts"); //Remove shortcuts var shcutPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory); // Environment.GetFolderPath(Environment.SpecialFolder.Desktop); //delete_Shortcut(shcutPath, appName); string appName = "Oracle VM VirtualBox"; FD.delete_Shortcut(shcutPath, appName, false); shcutPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory); var shcutStartPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu); //Folder files shcutPath = Path.Combine(shcutStartPath, "Programs"); //Uninstall.lnk FD.delete_Shortcut(shcutPath, appName, false); //Remove folder FD.delete_Shortcut(shcutPath, appName, true); clean.StageReporter("", "Removing from %Path%"); FD.remove_from_Path(dirStart); mesg = string.Format("Oracle VirtualBox removed from Your machine. \n\n Please do not forget to RESTART windows before new installation!"); MessageBox.Show(mesg, "Removing Oracle VirtualBox", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }