• .NET C# 获取Windows任务管理器中当前活动的程序进程的命令行参数信息


            /// <summary>
            /// 获取正在运行的程序实例的命令行参数信息
            /// </summary>
            /// <returns></returns>
            private static string GetRunningInstanceArgument()
            {
                var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                var processName = currentProcess.ProcessName;
                var processes = System.Diagnostics.Process.GetProcessesByName(processName);

         var currentProcess = processes.FirstOrDefault();

                var arguments = GetCommandLineArgsCore(currentProcess);

                return arguments;
            }
            private static string GetCommandLineArgsCore(Process process)
            {
                using (var searcher = new ManagementObjectSearcher(
                    "SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
                using (var objects = searcher.Get())
                {
                    var @object = objects.Cast<ManagementBaseObject>().SingleOrDefault();
                    return @object?["CommandLine"]?.ToString() ?? "";
                }
            }

  • 相关阅读:
    Mysql经常使用函数
    ZOJ 3690 Choosing number
    cocos2d-x 多触点监听
    ansible不配ssh连接,用户密码登录
    Ansible Role
    关闭centos自动升级内核
    让外部网络访问K8S service的四种方式
    Hadoop实战:Hadoop分布式集群部署(一)
    Docker:搭建私有仓库(Registry 2.4)
    Docker下的Spring Cloud三部曲之一:极速体验
  • 原文地址:https://www.cnblogs.com/jeff151013/p/16081746.html
Copyright © 2020-2023  润新知