Esempio n. 1
0
 void SuccessMessage(string al)
 {
     successalias = al;
     successalias = successalias.Replace(".exe", "");
     textBox1.Clear();
     textBox2.Clear();
     radioButton2.Checked = true;
     msg.ShowMessage("Success!\n\nTry running your new shortcut:\n\nStep 1: open Run Dialog Box (WIN+R)\n\nStep 2: type \"" + successalias + "\"\n\nStep 3: hit OK");
 }
        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);
            }
        }
Esempio n. 3
0
 void SuccessMessage(string al)
 {
     al = al.Replace(".exe", "");
     msg.ShowMessage("Success!\n\nTry running your new shortcut:\n\nStep 1: open Run Dialog Box (WIN+R)\n\nStep 2: type \"" + al + "\"\n\nStep 3: hit OK");
 }
Esempio n. 4
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);
            }
        }