ToString() public method

public ToString ( ) : string
return string
        public static string GetProcessCommandline(Process process)
        {
            try
            {
                Debug.Write(string.Format("FileName: {0}", process.MainModule.FileName ?? "<NULL>"));
                using (ManagementObjectSearcher searcher = GetProcessSearcherForId(process.Id))
                {
                    foreach (ManagementObject @object in searcher.Get())
                    {
                        string name = @object["CommandLine"] + " ";
                        Debug.WriteLine(string.Format("CommandLine: {0}", name));
                        return name.Trim();
                    }

                    Debug.WriteLine("");
                }
            }
            catch (Win32Exception ex)
            {
                if ((uint)ex.ErrorCode != 0x80004005)
                {
                    Debug.WriteLine(ex.Message);
                    throw;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Error reading process information for {0} : {1}", process.ToString(), ex.Message));
            }
            return null;
        }
Esempio n. 2
0
        private void Button_Test_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            System.Diagnostics.Process pro = System.Diagnostics.Process.GetCurrentProcess();

            Debug.WriteLine(pro.Id.ToString() + " / " + pro.ProcessName + " / " + pro.ToString());

            // Get a toast XML template
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

            Debug.WriteLine(toastXml.GetXml());

            // Fill in the text elements
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            for (int i = 0; i < stringElements.Length; i++)
            {
                stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
            }

            // Specify the absolute path to an image
            String imagePath = "file:///" + Path.GetFullPath("./Resources/Wopal_Beach.png");
            //String imagePath = "ms-appx:///Wopal_Beach.png";
            XmlNodeList imageElements = toastXml.GetElementsByTagName("image");

            imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

            Debug.WriteLine(imagePath);
            // Create the toast and attach event listeners
            ToastNotification toast = new ToastNotification(toastXml);

            toast.Activated += ToastActivated;
            toast.Dismissed += ToastDismissed;
            toast.Failed    += ToastFailed;

            // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
        }
        public static string TryFindOwnerAppDataPath(Process process)
        {
            try
            {
                using (ManagementObjectSearcher searcher = GetProcessSearcherForId(process.Id))
                {
                    foreach (ManagementObject @object in searcher.Get())
                    {
                        Debug.WriteLine("Found running process ");

                        string[] OwnerInfo = new string[2];
                        @object.InvokeMethod("GetOwner", (object[])OwnerInfo);

                        string username = OwnerInfo[0];
                        string domain = OwnerInfo[1];

                        Debug.WriteLine(string.Format(" Owner {0}\\{1}", domain, username));

                        string[] OwnerSid = new string[1];
                        @object.InvokeMethod("GetOwnerSid", (object[])OwnerSid);

                        string sid = OwnerSid[0];
                        Debug.WriteLine(string.Format(" SID: {0}", sid));

                        string path=Registry.GetValue(regKeyFolders.Replace("<SID>", sid), regValueAppData, null) as string;

                        Debug.WriteLine(string.Format("AppData: {0}", path == null ? "<NULL>" : path));

                        return path;
                    }
                }
            }
            catch (Win32Exception ex)
            {
                if ((uint)ex.ErrorCode != 0x80004005)
                {
                    Debug.WriteLine(ex.Message);
                    throw;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error reading process information for {0} : {1}", process.ToString(), ex.Message);
            }
            return null;
        }
Esempio n. 4
0
        /*static SubProcess()
        {
            StartProcessKiller();
        }

        /// <summary>
        /// Helper to start the process killer
        /// </summary>
        private static void StartProcessKiller()
        {
            try
            {
                Process pkp = new Process();
                pkp.StartInfo = new ProcessStartInfo("ProcessKiller.exe", Process.GetCurrentProcess().Id.ToString());
                pkp.StartInfo.RedirectStandardInput = true;
                pkp.StartInfo.UseShellExecute = false;

                pkp.EnableRaisingEvents = true;
                pkp.Exited += new EventHandler(pkp_Exited);

                if (!pkp.Start())
                {
                    Exception e = new JavascriptException("Could not start sub process");
                    log.Error("Error starting Process Killer sub process", e);

                    throw e;
                }

                log.Info("Process Killer started, parent process id (" + Process.GetCurrentProcess().Id.ToString() + "): " + pkp.ToString());

                SubProcessIdWriteStream = pkp.StandardInput;

                HashSet<Process> subProcesses;
                using (TimedLock.Lock(SubProcesses))
                    subProcesses = new HashSet<Process>(SubProcesses);

                using (TimedLock.Lock(SubProcessIdWriteStream))
                    foreach (Process subProcess in subProcesses)
                        SubProcessIdWriteStream.WriteLine(subProcess.Id.ToString());

            }
            catch (Exception e)
            {
                log.Error("Error starting process killer", e);
            }
        }

        static void pkp_Exited(object sender, EventArgs e)
        {
            ((Process)sender).Exited -= new EventHandler(pkp_Exited);
            StartProcessKiller();
        }*/
        public SubProcess(FileHandlerFactoryLocator fileHandlerFactoryLocator)
        {
            _Process = new Process();
            _Process.StartInfo = new ProcessStartInfo("java", "-cp ." + Path.DirectorySeparatorChar + "js.jar -jar JavascriptProcess.jar " + Process.GetCurrentProcess().Id.ToString());
            _Process.StartInfo.RedirectStandardInput = true;
            _Process.StartInfo.RedirectStandardOutput = true;
            _Process.StartInfo.RedirectStandardError = true;
            _Process.StartInfo.UseShellExecute = false;
            _Process.EnableRaisingEvents = true;
            _Process.Exited += new EventHandler(Process_Exited);

            log.Info("Starting sub process");

            if (!Process.Start())
            {
                Exception e = new JavascriptException("Could not start sub process");
                log.Error("Error starting Javascript sub process", e);

                throw e;
            }

            log.Info("Javascript sub process started: " + _Process.ToString());

            if (null != SubProcessIdWriteStream)
                using (TimedLock.Lock(SubProcessIdWriteStream))
                    SubProcessIdWriteStream.WriteLine(_Process.Id.ToString());

            JSONSender = new JsonWriter(_Process.StandardInput);

            // Failed attempt to handle processes without Threads
            _Process.ErrorDataReceived += new DataReceivedEventHandler(Process_ErrorDataReceived);
            _Process.BeginErrorReadLine();

            using (TimedLock.Lock(SubProcesses))
                SubProcesses.Add(_Process);
        }