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


C# ProcessHandle.GetEnvironmentVariables方法代码示例

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


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

示例1: UpdateEnvironmentVariables

        private void UpdateEnvironmentVariables()
        {
            listEnvironment.Items.Clear();
            listEnvironment.BeginUpdate();

            WorkQueue.GlobalQueueWorkItemTag(new MethodInvoker(() =>
            {
                try
                {
                    using (ProcessHandle phandle = new ProcessHandle(_pid, ProcessAccess.QueryInformation | Program.MinProcessReadMemoryRights))
                    {
                        foreach (KeyValuePair<string, string> pair in phandle.GetEnvironmentVariables())
                        {
                            if (!string.IsNullOrEmpty(pair.Key))
                            {
                                if (this.IsHandleCreated)
                                {
                                    // Work around delegate variable capturing.
                                    var localPair = pair;

                                    this.BeginInvoke(new MethodInvoker(() => this.listEnvironment.Items.Add(new ListViewItem(new[] { localPair.Key, localPair.Value }))));
                                }
                            }
                        }
                    }
                }
                catch
                { }

                if (this.IsHandleCreated)
                {
                    this.BeginInvoke(new MethodInvoker(() => listEnvironment.EndUpdate()));
                }
            }), "process-update-environment-variables");
        }
开发者ID:john-peterson,项目名称:processhacker,代码行数:35,代码来源:ProcessWindow.cs

示例2: GetProcessDetailsText


//.........这里部分代码省略.........
                            sb.AppendLine("    Version info failed! " + ex2.Message);
                        }

                        sb.AppendLine();
                    }
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine("Modules section failed! " + ex.Message);
            }

            sb.AppendLine("Token:");
            sb.AppendLine();

            try
            {
                using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryLimitedInformation))
                using (var thandle = phandle.GetToken(TokenAccess.Query))
                {
                    sb.AppendLine("User: " + thandle.GetUser().GetFullName(true));
                    sb.AppendLine("Owner: " + thandle.GetOwner().GetFullName(true));
                    sb.AppendLine("Primary group: " + thandle.GetPrimaryGroup().GetFullName(true));

                    foreach (var group in thandle.GetGroups())
                    {
                        sb.AppendLine("Group " + group.GetFullName(true));
                    }

                    foreach (var privilege in thandle.GetPrivileges())
                    {
                        sb.AppendLine("Privilege " + privilege.Name + ": " + privilege.Attributes.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine("Token section failed! " + ex.Message);
            }

            sb.AppendLine();
            sb.AppendLine("Environment:");
            sb.AppendLine();

            try
            {
                using (var phandle = new ProcessHandle(pid, ProcessAccess.QueryInformation | ProcessAccess.VmRead))
                {
                    var vars = phandle.GetEnvironmentVariables();

                    foreach (var kvp in vars)
                    {
                        sb.AppendLine(kvp.Key + " = " + kvp.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine("Environment section failed! " + ex.Message);
            }

            sb.AppendLine();
            sb.AppendLine("Handles:");
            sb.AppendLine();

            try
            {
                using (var phandle = new ProcessHandle(pid, ProcessAccess.DupHandle))
                {
                    var handles = Windows.GetHandles();

                    foreach (var handle in handles)
                    {
                        if (handle.ProcessId != pid)
                            continue;

                        sb.Append("[0x" + handle.Handle.ToString("x") + ", ");

                        try
                        {
                            var info = handle.GetHandleInfo(phandle);

                            sb.Append(info.TypeName + "] ");
                            sb.AppendLine(!string.IsNullOrEmpty(info.BestName) ? info.BestName : "(no name)");
                        }
                        catch (Exception ex2)
                        {
                            sb.Append(handle.ObjectTypeNumber.ToString() + "] ");
                            sb.AppendLine("Error: " + ex2.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine("Handles section failed! " + ex.Message);
            }

            return sb.ToString();
        }
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:101,代码来源:Save.cs

示例3: UpdateEnvironmentVariables

        private void UpdateEnvironmentVariables()
        {
            listEnvironment.Items.Clear();

            listEnvironment.BeginUpdate();

            WorkQueue.GlobalQueueWorkItemTag(new Action(() =>
                {
                    try
                    {
                        using (ProcessHandle phandle = new ProcessHandle(_pid,
                            ProcessAccess.QueryInformation | Program.MinProcessReadMemoryRights))
                        {
                            foreach (var pair in phandle.GetEnvironmentVariables())
                            {
                                if (pair.Key != "")
                                {
                                    if (this.IsHandleCreated)
                                    {

                                        var localPair = pair;

                                        this.BeginInvoke(new MethodInvoker(() =>
                                        {
                                            listEnvironment.Items.Add(
                                                new ListViewItem(new string[] { localPair.Key, localPair.Value }));
                                        }));
                                    }
                                }
                            }
                        }
                    }
                    catch
                    { }

                    if (this.IsHandleCreated)
                    {
                        this.BeginInvoke(new MethodInvoker(() => listEnvironment.EndUpdate()));
                    }
                }), "process-update-environment-variables");
        }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:41,代码来源:ProcessWindow.cs


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