Beispiel #1
0
        private bool PerformAction(string action)
        {
            Log.InfoFormat("{0}.PerformAction({1}) called", this, action);
            try
            {
                if (string.IsNullOrEmpty(action))
                {
                    Log.Warn("Warning, action is empty - assume function failed");
                    return(false);
                }

                string cmd  = PathSanitizer.GetExecutable(action);
                string args = PathSanitizer.GetArguments(action);
                Log.InfoFormat("CMD: {0}, ARGS: {1}", cmd, args);

                using (Process p = Process.Start(cmd, args))
                {
                    if (p == null)
                    {
                        Log.Warn("Warning, Process.Start() returned null, assuming function failed");
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Error(string.Format("unable to run action {0}", action), e);
                return(false);
            }
        }
Beispiel #2
0
        public static bool DebugProcessById(int id)
        {
            using (RegistryKey hkKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug", false))
            {
                string debugger = hkKey.GetValue("Debugger") as string;
                if (string.IsNullOrEmpty(debugger))
                {
                    return(false);
                }

                // problem: %ld is not a recognized format sequence in C#, so:

                int k = debugger.IndexOf("%ld");
                if (k >= 0)
                {
                    debugger = debugger.Substring(0, k) + id.ToString() + debugger.Substring(k + 3);
                }
                k = debugger.IndexOf("%ld");
                if (k >= 0)
                {
                    debugger = debugger.Substring(0, k) + "0" + debugger.Substring(k + 3);
                }


                string cmdLine = debugger;

                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(PathSanitizer.GetExecutable(cmdLine));
                    startInfo.WorkingDirectory = Environment.CurrentDirectory;
                    startInfo.Arguments        = PathSanitizer.GetArguments(cmdLine);

                    using (Process p = Process.Start(startInfo))
                    {
                        if (p == null)
                        {
                            Log.Warn("Warning, Process.Start() returned null, assuming function failed");
                            return(false);
                        }
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Log.Error(string.Format("unable to bring up debugger: {0}", cmdLine), e);
                    return(false);
                }
            }
        }