当前位置: 首页>>代码示例>>C#>>正文


C# Process.ToString方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Process.ToString方法的具体用法?C# Process.ToString怎么用?C# Process.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetProcessCommandline

        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;
        }
开发者ID:BEASTLICK-INTERNET-POLICY-COMMISSION,项目名称:MeowBit,代码行数:31,代码来源:ProcessUtils.cs

示例2: TryFindOwnerAppDataPath

        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;
        }
开发者ID:BEASTLICK-INTERNET-POLICY-COMMISSION,项目名称:MeowBit,代码行数:46,代码来源:ProcessUtils.cs

示例3: StartProcessKiller

        /*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);
        }
开发者ID:GWBasic,项目名称:ObjectCloud,代码行数:88,代码来源:SubProcess.cs


注:本文中的System.Diagnostics.Process.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。