Exemplo n.º 1
0
        private static void RunFileAction(string scriptFile, string actionName, string defaultRun, bool asAdmin)
        {
            if (string.IsNullOrEmpty(scriptFile)) { return; }
            if (!System.IO.File.Exists(scriptFile)) { return; }

            var option = GetConfigOption(scriptFile, actionName);
            if (option == null)
            {
                option = new ScriptOpenOption { ActionType = actionName, RunCommand = defaultRun };
            }

            System.Diagnostics.ProcessStartInfo pi = null;
            if (string.IsNullOrEmpty(option.RunCommand))
            {
                pi = new System.Diagnostics.ProcessStartInfo(scriptFile);
            }
            else
            {
                pi = new System.Diagnostics.ProcessStartInfo(option.RunCommand, string.Format(option.RunArgsFormat, scriptFile));
                //pi.UseShellExecute = false;
            }

            if (asAdmin == true)
            {
                pi.Verb = "runas";
            }

            System.Diagnostics.Process.Start(pi);
        }
Exemplo n.º 2
0
        private static List<ScriptOpenOption> GetConfigOptions()
        {
            var lsOptions = new List<ScriptOpenOption>();

            if (!System.IO.File.Exists(ExtensionHandlersConfigFile)) { return lsOptions; }

            using (var sr = new System.IO.StreamReader(ExtensionHandlersConfigFile))
            {
                do
                {
                    string szLine = sr.ReadLine();
                    if (string.IsNullOrEmpty(szLine) || szLine.StartsWith(COMMENT_CHAR)) { continue; }

                    var arValues = szLine.Split(ARG_SEPERATOR);
                    //if (arValues.Length  3) { continue; } // its invalid, ignore it

                    var opt = new ScriptOpenOption(arValues);
                    if (opt.IsValid()) { lsOptions.Add(opt); }
                } while (!sr.EndOfStream);
            }

            return lsOptions;
        }