Esempio n. 1
0
        /// <summary>
        /// Removing Oracle VirtualBox - short version.
        /// Using official msi uninstall
        /// </summary>
        /// <param name="app_name">Name of the application.</param>
        public static void remove_app_vbox_short(string app_name)
        {
            if (AP.app_installed("Oracle\\VirtualBox") == 0)
            {
                MessageBox.Show("Oracle VirtualBox is not installed on Your machine", "Removing Oracle VirtualBox", MessageBoxButtons.OK);
                return;
            }

            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 try to remove {app_name} if uninstalling from Control Panel. Note: it is better to remove {app_name} separately.", $"Removing {app_name}",
            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;
                    }
                }
            }
            clean.StageReporter("", "Removing VirtualBox software");
            //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\6FBF3FE4D796A044AAADF7D5937BE326\InstallProperties
            string subkey        = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products";
            string uninstall_str = RG.find_and_get_value(subkey, "VirtualBox", "UninstallString", RegistryHive.LocalMachine);

            res = "";
            if (uninstall_str != "")
            {
                string[] uninst = uninstall_str.Split(' ');
                res = SCP.LaunchCommandLineApp(uninst[0], uninst[1], true, false);
            }
            //MessageBox.Show(res, "Uninstalling VirtualBox", MessageBoxButtons.OK);

            mesg = "";
            if (AP.app_installed("Oracle\\VirtualBox") == 0)
            {
                mesg = string.Format("Oracle VirtualBox removed from Your machine. \n\n Please do not forget to RESTART windows before new installation!");
            }
            else
            {
                mesg = string.Format("Oracle VirtualBox was not removed from Your machine");
            }
            MessageBox.Show(mesg, "Removing Oracle VirtualBox", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the application.
        /// </summary>
        /// <param name="app_name">Name of the application.</param>
        /// <param name="cmd">The command.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="app_path">The application path.</param>
        public static void remove_app(string app_name, string cmd, string args, string app_path)
        {
            string mess = "";

            if (File.Exists(cmd))
            {
                string res = SCP.LaunchCommandLineApp(cmd, args, false, false, 480000);
                if (res.Contains("|Error") || res.ToLower().Contains("error"))
                {
                    mess = $"{app_name} was not removed, please uninstall manually";
                }
                else
                {
                    mess = $"{app_name} uninstalled";
                }
            }
            else
            {
                mess = $"Probably {app_name} was not installed, please check and uninstall manually";
            }
            //MessageBox.Show(mess, $"Uninstalling {app_name}", MessageBoxButtons.OK);
            if (app_path != "" || app_path != null)
            {
                FD.remove_from_Path(app_path);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deleting TAP software.
        /// </summary>
        public static void del_TAP()
        {
            string binPath = Path.Combine(clean.sysDrive, "Program Files", "TAP-Windows", "bin", "tapinstall.exe");
            string res     = "";

            if (File.Exists(binPath))
            {
                res = SCP.LaunchCommandLineApp(binPath, "remove tap0901", true, false, 480000);
            }
            binPath = Path.Combine(clean.sysDrive, "Program Files", "TAP-Windows", "Uninstall.exe");
            string pathPath = Path.Combine(clean.sysDrive, "Program Files", "TAP-Windows", "bin");

            if (clean.bTAP)
            {
                remove_app("TAP-Windows", binPath, "/S", "TAP-Windows");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Remove host only interfaces.
        /// </summary>
        public static void remove_host_only()
        {
            string res = SCP.LaunchCommandLineApp("cmd.exe", " /C vboxmanage list hostonlyifs| findstr /b \"Name:\"", true, false, 300000);

            string[] splitted = res.Split('|');
            //res = res.Remove(0, res.IndexOf("stdout"));
            //res = res.Substring(0, res.IndexOf("stderr"));
            //res = res.Replace("stdout:","");
            res = splitted[2].Replace("Name:", "");
            string[] ifaces = res.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (string iface in ifaces)
            {
                string tmp = iface.Trim(' ');
                if (tmp == "" || iface == null)
                {
                    continue;
                }
                clean.StageReporter("", $"Removing {tmp}");
                res = SCP.LaunchCommandLineApp("vboxmanage ", $" hostonlyif remove \"{tmp}\"", true, false, 420000);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Removing virtual machines containing "snappy" or "subutai" in names.
        /// </summary>
        public static bool remove_vm()
        {
            string outputList = SCP.LaunchCommandLineApp("vboxmanage", $"list vms", true, false, 420000);

            string[] outputListSplitted = outputList.Split('|');
            string   outputVms          = outputListSplitted[1];

            if (outputVms.ToLower().Contains("error") || outputVms.ToLower().Contains("can not"))
            {
                return(false);
            }
            string msg = "";

            string[] rows = Regex.Split(outputVms, "\n");
            foreach (string row in rows)
            {
                if (row.Contains("subutai") || row.Contains("snappy"))
                {
                    string[] wrds = row.Split('{');
                    foreach (string wrd in wrds)
                    {
                        if (wrd.Contains("subutai") || wrd.Contains("snappy"))
                        {
                            string vmName = wrd.Replace("\"", "");
                            vmName = vmName.Trim();
                            string res1 = SCP.LaunchCommandLineApp("vboxmanage", $"controlvm \"{vmName}\" poweroff ", true, false, 420000);
                            string res2 = SCP.LaunchCommandLineApp("vboxmanage", $"unregistervm  --delete \"{vmName}\"", true, false, 420000);
                            if (res2.ToLower().Contains("error"))
                            {
                                msg = string.Format("VM {0} was not removed, please delete VM {1} and it's files manually \n and check logs in <SystemDrive>:\\Users\\<UserName>\\.Virtualbox folfer", vmName, vmName);
                                MessageBox.Show(msg, "Deleting Virtual Machine", MessageBoxButtons.OK);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 6
0
        /// <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);
        }