예제 #1
0
        private void SelfIntegrationInitChecks()
        {
            try
            {
                // string ExistingTarget = (string)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\er.exe").GetValue("");


                string      curr   = System.Reflection.Assembly.GetExecutingAssembly().Location;
                EasyRun.res newres = new EasyRun.res();
                curr = newres.getLocation(curr);



                if (!Directory.Exists(SELF_SHORTCUT_PATH))
                {
                    Directory.CreateDirectory(SELF_SHORTCUT_PATH);
                }
                if (!Directory.Exists(SAFE_LOCATION_DIRECTORY))
                {
                    Directory.CreateDirectory(SAFE_LOCATION_DIRECTORY);
                }



                string sfelocation = SELF_SHORTCUT_PATH + "EasyRun.exe";



                try
                {
                    if (curr != @"C:\Program Files\EasyRun")
                    {
                        System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, SELF_SHORTCUT_PATH + "EasyRun.exe", true);
                        CopyLibrary(lib1, SELF_SHORTCUT_PATH + "Interop.IWshRuntimeLibrary.dll");
                        CopyLibrary(lib2, SELF_SHORTCUT_PATH + "Microsoft.Win32.TaskScheduler.dll");
                        CopyLibrary(lib3, SELF_SHORTCUT_PATH + "Explintegrate.dll");
                        CopyLibrary(lib4, SELF_SHORTCUT_PATH + "CommandLine.dll");
                    }
                }

                catch (Exception exp)
                {
                    msg.ShowError(exp.Message);
                }
            }
            catch (Exception e) {
                msg.ShowError(e.Message + "\n\nRaw:\n\n" + e.ToString());
            }
        }
예제 #2
0
        private void addERDelegate()
        {
            try {
                string sfelocation = SELF_SHORTCUT_PATH + "EasyRun.exe";

                SelfIntegrationInitChecks();


                TaskService    tsObj = new TaskService();
                TaskDefinition tsDef = tsObj.NewTask();
                tsDef.Principal.RunLevel = TaskRunLevel.Highest;
                tsDef.Actions.Add(new ExecAction(sfelocation));
                tsDef.Settings.AllowDemandStart           = true;
                tsDef.RegistrationInfo.Author             = "EasyRun";
                tsDef.RegistrationInfo.Description        = "Start EasyRun control panel on-demand";
                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;
                string tskname = "EasyRunUACDelegate";
                tsObj.RootFolder.RegisterTaskDefinition("EasyRunUACDelegate", tsDef);
                string cmd   = "@echo off" + Environment.NewLine + @"C:\Windows\System32\schtasks.exe /run /tn EasyRunUACDelegate" + Environment.NewLine + "exit";
                string alias = "er.exe";
                tskname += ".cmd";
                string cmd_file = SAFE_LOCATION_DIRECTORY + tskname;
                System.IO.File.WriteAllText(cmd_file, cmd);
                string      action_file_selected_path = cmd_file;
                EasyRun.res x1            = new EasyRun.res();
                string      location_temp = x1.getLocation(cmd_file);
                try
                {
                    string EXISTING_ALIAS_FILEMAPPED = (string)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\er.exe").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);
                    FileVersionInfo ins = FileVersionInfo.GetVersionInfo(action_file_selected_path);
                    Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\er.exe").Close();
                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\er.exe", true).SetValue("", action_file_selected_path);
                    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\er.exe", true).SetValue("Path", location_temp + @"\");
                    SuccessMessage("er");
                    return;
                }
                catch (NullReferenceException excep)
                {
                    FileVersionInfo ins = FileVersionInfo.GetVersionInfo(action_file_selected_path);
                    // DialogResult re = MessageBox.Show("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?", "Confirm Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    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 + @"\");
                    SuccessMessage("er");
                    return;
                }
            }
            catch (Exception exp)
            {
                msg.ShowError(exp.Message);
            }
        }
예제 #3
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);
            }
        }