Пример #1
0
        public void CreateIntegration(bool silent)
        {
            try
            {
                string command_str_file_assoc = AppDomain.CurrentDomain.BaseDirectory + "EasyRun.exe --add-file \"%1\"";
                string command_str_dir_assoc  = AppDomain.CurrentDomain.BaseDirectory + "EasyRun.exe --add-dir \"%1\"";


                if (DeleteIntegration() == 0)
                {
                    //creating file assoc
                    expl.CreateAssociation("*", KeyName, command_str_file_assoc, "Add as EasyRun shortcut", AppDomain.CurrentDomain.BaseDirectory + "EasyRun.exe");

                    //creating directory assoc
                    expl.CreateAssociation("Directory", KeyName, command_str_dir_assoc, "Add as EasyRun shortcut", AppDomain.CurrentDomain.BaseDirectory + "EasyRun.exe");

                    if (!silent)
                    {
                        msg.ShowMessage("Explorer Integration has been enabled successfully");
                    }
                }
                else
                {
                    msg.ShowWarning("The requested operation failed. an error occured while trying to unregistering handlers.");
                }
            }
            catch (Exception ex)
            {
                msg.ShowError(ex.Message);
            }
        }
Пример #2
0
        public void askUser(string title, bool Show_Mru_Clear_CB, string formTitle)
        {
            try
            {
                Form     foo         = new Form();
                TextBox  tb          = new TextBox();
                CheckBox CB_ClearMru = new CheckBox();
                CB_ClearMru.Text = "Clear Run MRU on execution";
                RadioButton rb_onlyme = new RadioButton();
                rb_onlyme.Text = "Just me";
                RadioButton rb_all = new RadioButton();
                rb_all.Text = "All users";
                Button accept = new Button();
                Label  val    = new Label();


                val.Text     = title;
                val.AutoSize = true;


                CB_ClearMru.AutoSize = true;
                CB_ClearMru.Checked  = false;

                val.Location    = new Point(12, 10);
                tb.Location     = new Point(12, 34);
                accept.Location = new Point(188, 31);
                accept.Size     = new Size(75, 23);

                accept.FlatStyle = FlatStyle.Flat;

                accept.UseVisualStyleBackColor = false;

                accept.BackColor = Color.Transparent;

                accept.BackgroundImage = Properties.Resources.normal;

                accept.MouseDown += delegate(object sender, MouseEventArgs e)
                {
                    accept.BackgroundImage = Properties.Resources.click;
                };

                accept.MouseEnter += delegate(object sender, EventArgs e)
                {
                    accept.BackgroundImage = Properties.Resources.hover;
                };

                accept.MouseUp += delegate(object sender, MouseEventArgs e)
                {
                    accept.BackgroundImage = Properties.Resources.hover;
                };
                accept.MouseLeave += delegate(object sender, EventArgs e)
                {
                    accept.BackgroundImage = Properties.Resources.normal;
                };
                accept.FlatAppearance.BorderSize         = 0;
                accept.FlatAppearance.MouseDownBackColor = Color.Transparent;
                accept.FlatAppearance.MouseOverBackColor = Color.Transparent;


                foo.Controls.Add(val);
                foo.Controls.Add(tb);
                foo.Controls.Add(accept);

                foo.Icon = Properties.Resources.Dakirby309_Simply_Styled_Run;


                foo.ShowIcon      = true;
                foo.ShowInTaskbar = true;
                foo.BackColor     = Color.White;

                foo.Text            = formTitle;
                foo.AllowDrop       = false;
                foo.FormBorderStyle = FormBorderStyle.FixedSingle;
                tb.Size             = new Size(new Point(165, 20));
                accept.Text         = "OK";
                tb.KeyDown         += delegate(object sender, KeyEventArgs e)
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        accept.PerformClick();
                    }
                    if (e.KeyCode == Keys.Escape)
                    {
                        if (msg.ConfirmAction("Do you want to exit?") == DialogResult.Yes)
                        {
                            Application.Exit();
                        }
                    }
                };
                CB_ClearMru.KeyDown += delegate(object sender, KeyEventArgs e)
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        accept.PerformClick();
                    }
                };
                accept.Click += delegate
                {
                    if (string.IsNullOrEmpty(tb.Text) || string.IsNullOrWhiteSpace(tb.Text) || tb.Text.Contains(" "))
                    {
                        msg.ShowWarning("Alias cannot be empty or contain spaces");
                    }
                    else
                    {
                        if (CB_ClearMru.Checked)
                        {
                            clearMRU = true;
                        }
                        userInput = tb.Text;
                        foo.Close();
                    }
                };

                foo.KeyDown += delegate(object sender, KeyEventArgs e)
                {
                    if (e.KeyCode == Keys.Escape)
                    {
                        if (msg.ConfirmAction("Do you want to exit?") == DialogResult.Yes)
                        {
                            Application.Exit();
                        }
                    }
                };

                foo.FormClosing += delegate
                {
                    if (string.IsNullOrEmpty(tb.Text))
                    {
                        Environment.Exit(0);
                    }
                    userInput = tb.Text;
                };

                foo.MaximizeBox = false;

                foo.MinimizeBox   = false;
                foo.StartPosition = FormStartPosition.CenterScreen;

                foo.Width  = 284;
                foo.Height = 108;
                if (Show_Mru_Clear_CB)
                {
                    CB_ClearMru.Location = new Point(12, 60);
                    foo.Controls.Add(CB_ClearMru);
                    foo.Height = 115;
                }


                foo.ShowDialog();
                tb.Focus();
                tb.Select();
            }
            catch (Exception ex)
            {
                msg.ShowError(ex.Message);
            }
        }
Пример #3
0
        private void ClickBait()
        {
            try
            {
                if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
                {
                    msg.ShowWarning("One or more required fields is missing values");
                }
                else if (textBox1.Text == alias && textBox2.Text == target)
                {
                    inst.editDropped = 1; //bail immediately cause no changes

                    this.Close();
                }
                else if (textBox1.Text.Contains(" "))
                {
                    msg.ShowWarning("Alias cannot be empty or contain white spaces.");
                }
                else
                {
                    if (textBox1.Text.Contains(".") == false || textBox1.Text.Substring(textBox1.Text.LastIndexOf(".")) != ".exe")
                    {
                        textBox1.Text = textBox1.Text + ".exe";
                    }
                    newalias  = textBox1.Text;
                    newtarget = textBox2.Text;
                    var resul = msg.ConfirmAction("Are you sure you want to confirm changes?");
                    if (resul == DialogResult.Yes)
                    {
                        if (access == "HKLM")
                        {
                            Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias).Close();
                            Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias, true).SetValue("", newtarget);
                            Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias, true).SetValue("Path", newtarget.Substring(0, newtarget.LastIndexOf(@"\")) + @"\");
                            if (newalias != alias)
                            {
                                Registry.LocalMachine.DeleteSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\" + alias, false);
                            }

                            result           = 1;
                            inst.editDropped = 0; //trigger list refresh
                            this.Close();
                        }
                        else if (access == "HKCU")
                        {
                            Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias).Close();
                            Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias, true).SetValue("", newtarget);
                            Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + newalias, true).SetValue("Path", newtarget.Substring(0, newtarget.LastIndexOf(@"\")) + @"\");
                            if (newalias != alias)
                            {
                                Registry.CurrentUser.DeleteSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\" + alias, false);
                            }

                            result           = 1;
                            inst.editDropped = 0; //trigger list refresh

                            this.Close();
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                msg.ShowError(exp.Message);
            }
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                short ret_ptr = CheckSettings();
                if (ret_ptr == 0)
                {
                    try
                    {
                        string EXISTING_ALIAS_FILEMAPPED = (string)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ALIAS).GetValue("");
                        string regexSearch = new string(Path.GetInvalidPathChars());
                        Regex  r           = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
                        EXISTING_ALIAS_FILEMAPPED = r.Replace(EXISTING_ALIAS_FILEMAPPED, "");
                        FileVersionInfo inf = FileVersionInfo.GetVersionInfo(EXISTING_ALIAS_FILEMAPPED);
                        DialogResult    res = msg.ConfirmAction("A shortcut with the name you specified already exists\n\nDetails\n-------\nAlias: " + ALIAS + "\n\nDescription: " + inf.FileDescription + "\nFile: " + EXISTING_ALIAS_FILEMAPPED.Substring(EXISTING_ALIAS_FILEMAPPED.LastIndexOf(@"\") + 1) + "\nPath: " + EXISTING_ALIAS_FILEMAPPED + "\n\nWould you like to overwrite it?");

                        if (res == DialogResult.Yes)
                        {
                            WriteAlias();
                        }
                    }
                    catch (NullReferenceException excep)
                    {
                        FileVersionInfo ins = FileVersionInfo.GetVersionInfo(ACTION_FILE_SELECTED_FILEPATH);
                        DialogResult    re  = msg.ConfirmAction("Confirm new shortcut:\n\nDetails\n------\nNew Alias:  " + ALIAS + "\nWho can use this shortcut:  " + OPTION_WHO_CAN_USE + "\nUsing Safe Location:  " + OPTION_SELECTED_USESAFELOCATION + "\n\nFile:  " + ACTION_FILE_SELECTED_FILENAME + "\nDescription:  " + ins.FileDescription + "\nPath:  " + ACTION_FILE_SELECTED_FILELOCATION + "\n\nWould you like to proceed?");
                        if (re == DialogResult.Yes)
                        {
                            WriteAlias();
                        }
                    }
                }
                else if (ret_ptr == 1)
                {
                    msg.ShowWarning("One or more required fields are missing values.");
                    return;
                }
                else if (ret_ptr == 2)
                {
                    msg.ShowWarning("The specified path is not valid");
                    return;
                }
                else if (ret_ptr == 3)
                {
                    msg.ShowWarning("The specified path is not valid");
                    return;
                }
                else if (ret_ptr == 5)
                {
                    msg.ShowWarning("Alias cannot be empty or contain Spaces.");
                    return;
                }
                else if (ret_ptr == -1)
                {
                    msg.ShowWarning("An internal error occured.");
                    return;
                }
            }
            catch (Exception ex)
            {
                msg.ShowError(ex.Message);
            }
        }
Пример #5
0
        private void Act()
        {
            try
            {
                if (!Directory.Exists(SAFE_LOCATION_DIRECTORY))
                {
                    Directory.CreateDirectory(SAFE_LOCATION_DIRECTORY);
                }



                if (string.IsNullOrEmpty(textBox1.Text) || !System.IO.File.Exists(textBox1.Text))
                {
                    msg.ShowWarning("One or more required fields are missing values");
                }
                else if (checkBox2.Checked == true && string.IsNullOrEmpty(textBox4.Text))
                {
                    msg.ShowWarning("Alias cannot be empty or contain spaces");
                }
                else if (checkBox2.Checked == true && textBox4.Text.Contains(" "))
                {
                    msg.ShowWarning("Alias cannot be empty or contain spaces");
                }
                else
                {
                    var resul = msg.ConfirmAction("Do you want to confirm changes?");
                    if (resul == DialogResult.Yes)
                    {
                        propargs = textBox2.Text;
                        wdir     = textBox3.Text;
                        TaskService    tsObj = new TaskService();
                        TaskDefinition tsDef = tsObj.NewTask();
                        tsDef.Principal.RunLevel = TaskRunLevel.Highest;
                        tsDef.Actions.Add(new ExecAction(exec, propargs, wdir));
                        tsDef.Settings.AllowDemandStart           = true;
                        tsDef.RegistrationInfo.Author             = "EasyRun";
                        tsDef.RegistrationInfo.Description        = "Allows creation of Trusted UAC Shortcuts by the user";
                        tsDef.Principal.DisplayName               = filename;
                        tsDef.Settings.AllowHardTerminate         = true;
                        tsDef.Settings.DisallowStartIfOnBatteries = false;
                        tsDef.Settings.MultipleInstances          = TaskInstancesPolicy.StopExisting;
                        tsDef.Settings.Enabled = true;
                        tsDef.Settings.StopIfGoingOnBatteries = false;
                        tsDef.Settings.WakeToRun = true;
                        tskname = "EasyRun-" + filename;
                        tsObj.RootFolder.RegisterTaskDefinition("EasyRun-" + filename, tsDef);
                        if (addsh == true)
                        {
                            string      x   = "\"" + tskname + "\"";
                            string      cmd = "@echo off" + Environment.NewLine + @"C:\Windows\System32\schtasks.exe /run /tn " + x + Environment.NewLine + "exit";
                            EasyRun.res x1  = new EasyRun.res();
                            tskname  = x1.removeExtension(tskname);
                            tskname += ".cmd";
                            string cmd_file = SAFE_LOCATION_DIRECTORY + tskname;
                            System.IO.File.WriteAllText(cmd_file, cmd);
                            action_file_selected_path = cmd_file;
                            location_temp             = x1.getLocation(cmd_file);
                            WshShellClass wsh = new WshShellClass();
                            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + tskname + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
                            shortcut.Description = "EasyRun Trusted UAC Bypass shortcut for " + tskname;
                            shortcut.WindowStyle = 1;
                            shortcut.TargetPath  = action_file_selected_path;
                            shortcut.Save();
                        }
                        if (checkBox2.Checked)
                        {
                            tskname = "EasyRun-" + filename;
                            alias   = textBox4.Text;
                            alias  += ".exe";
                            string      x   = "\"" + tskname + "\"";
                            string      cmd = "@echo off" + Environment.NewLine + @"C:\Windows\System32\schtasks.exe /run /tn " + x + Environment.NewLine + "exit";
                            EasyRun.res x1  = new EasyRun.res();
                            tskname  = x1.removeExtension(tskname);
                            tskname += ".cmd";
                            string cmd_file = SAFE_LOCATION_DIRECTORY + tskname;
                            System.IO.File.WriteAllText(cmd_file, cmd);
                            action_file_selected_path = cmd_file;
                            location_temp             = x1.getLocation(cmd_file);
                            try
                            {
                                string EXISTING_ALIAS_FILEMAPPED = (string)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias).GetValue("");
                                string regexSearch = new string(Path.GetInvalidPathChars());
                                Regex  r           = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
                                EXISTING_ALIAS_FILEMAPPED = r.Replace(EXISTING_ALIAS_FILEMAPPED, "");
                                FileVersionInfo inf = FileVersionInfo.GetVersionInfo(EXISTING_ALIAS_FILEMAPPED);
                                DialogResult    res = msg.ConfirmAction("A shortcut already exists with the name: " + alias + "\n\nDetails\n-------\nAlias: " + alias + "\n\nDescription: " + inf.FileDescription + "\nFile: " + EXISTING_ALIAS_FILEMAPPED.Substring(EXISTING_ALIAS_FILEMAPPED.LastIndexOf(@"\") + 1) + "\nPath: " + EXISTING_ALIAS_FILEMAPPED + "\n\nWould you like to overwrite it?");
                                if (res == DialogResult.Yes)
                                {
                                    FileVersionInfo ins = FileVersionInfo.GetVersionInfo(action_file_selected_path);
                                    Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias).Close();
                                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias, true).SetValue("", action_file_selected_path);
                                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias, true).SetValue("Path", location_temp + @"\");
                                    msg.ShowMessage("Success!");
                                    return;
                                }
                            }
                            catch (NullReferenceException excep)
                            {
                                FileVersionInfo ins = FileVersionInfo.GetVersionInfo(action_file_selected_path);
                                DialogResult    re  = msg.ConfirmAction("Confirm new shortcut:\n\nDetails\n------\nNew Alias:  " + alias + "\n\nFile:  " + action_file_selected_path + "\nDescription:  " + ins.FileDescription + "\nPath:  " + location_temp + "\n\nWould you like to proceed?");

                                if (re == DialogResult.Yes)
                                {
                                    Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias).Close();
                                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias, true).SetValue("", action_file_selected_path);
                                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + alias, true).SetValue("Path", location_temp + @"\");
                                    msg.ShowMessage("Success!");
                                    return;
                                }
                            }
                        }
                        msg.ShowMessage("Success!");
                    }
                }
            }
            catch (Exception exp)
            {
                msg.ShowError(exp.Message);
            }
        }
Пример #6
0
        void RefreshList()
        {
            try
            {
                textBox2.Clear();
                con_hkcu = 0;
                con_hklm = 0;
                toolStripStatusLabel1.Text = "Loading...";
                Cursor                   = Cursors.WaitCursor;
                listView1.Enabled        = false;
                textBox2.Enabled         = false;
                toolStripButton1.Enabled = false;
                menuStrip1.Enabled       = false;
                try
                {
                    listView1.Clear();
                    listView1.View = View.Details;
                    listView1.Columns.Add("Alias");
                    listView1.Columns.Add("Publisher");
                    listView1.Columns.Add("Image Path");
                    listView1.Columns.Add("Description");
                    listView1.Columns.Add("Type");
                    listView1.Columns.Add("Registry");
                    string ALIAS       = null;
                    string target      = null;
                    string description = null;
                    string hive        = null;
                    using (RegistryKey keyh = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths"))
                    {
                        if (keyh != null)
                        {
                            foreach (string keyname in keyh.GetSubKeyNames())
                            {
                                try
                                {
                                    ALIAS = keyname;
                                    RegistryKey item = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\" + keyname);
                                    target = (string)item.GetValue("");
                                    FileVersionInfo h = FileVersionInfo.GetVersionInfo(target);
                                    description = h.FileDescription;
                                    if (String.IsNullOrEmpty(h.CompanyName))
                                    {
                                        Publisher = "Unknown";
                                    }
                                    else
                                    {
                                        Publisher = h.CompanyName;
                                    }
                                    extension = target.Substring(target.LastIndexOf(".") + 1).ToUpper();
                                    hive      = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ALIAS;
                                    listView1.Items.Add(new ListViewItem(new string[] { ALIAS, Publisher, target, description, extension, hive }));
                                    con_hkcu++;
                                }
                                catch (Exception ex) { continue; }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Error: No items under HKCU");
                        }
                    }
                    if (listView1.SelectedItems.Count > 0)
                    {
                        listView1.SelectedItems.Clear();
                    }


                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths"))
                    {
                        if (key != null)
                        {
                            foreach (string keyname in key.GetSubKeyNames())
                            {
                                try
                                {
                                    ALIAS = keyname;
                                    RegistryKey item = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\" + keyname);
                                    target = (string)item.GetValue("");
                                    FileVersionInfo h = FileVersionInfo.GetVersionInfo(target);
                                    description = h.FileDescription;
                                    if (String.IsNullOrEmpty(h.CompanyName))
                                    {
                                        Publisher = "Unknown";
                                    }
                                    else
                                    {
                                        Publisher = h.CompanyName;
                                    }
                                    hive      = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ALIAS;
                                    extension = target.Substring(target.LastIndexOf(".") + 1).ToUpper();
                                    listView1.Items.Add(new ListViewItem(new string[] { ALIAS, Publisher, target, description, extension, hive }));
                                    con_hklm++;
                                }
                                catch (Exception ex) { continue; }
                            }
                        }
                        else
                        {
                            msg.ShowWarning("No aliases found on this computer");
                        }
                    }
                    if (listView1.SelectedItems.Count > 0)
                    {
                        listView1.SelectedItems.Clear();
                    }
                }
                catch (Exception exp)
                {
                    msg.ShowError(exp.Message);
                }

                con = listView1.Items.Count;

                toolStripStatusLabel1.Text = con + " items (Local: " + con_hkcu + " | Machine: " + con_hklm + ")";
                listView1.Columns[0].Width = 130;
                listView1.Columns[1].Width = 135;
                listView1.Columns[2].Width = 350;
                listView1.Columns[3].Width = 200;
                listView1.Columns[4].Width = 50;
                listView1.Columns[5].Width = 600;
                Cursor                   = Cursors.Default;
                listView1.Enabled        = true;
                textBox2.Enabled         = true;
                toolStripButton1.Enabled = true;
                menuStrip1.Enabled       = true;
                textBox2.Focus();
                if (listView1.SelectedItems.Count > 0)
                {
                    listView1.SelectedItems.Clear();
                }
            }
            catch (Exception exp)
            {
                msg.ShowError(exp.Message);
            }
        }