public List <WindowsProcess> GetWindowsProcesses()
        {
            List <WindowsProcess> windowsProcesses = new List <WindowsProcess>();

            try
            {
                foreach (var process in Process.GetProcesses())
                {
                    WindowsProcess windowsProcess = new WindowsProcess();
                    windowsProcess.BasePriority    = process.BasePriority;
                    windowsProcess.Id              = process.Id;
                    windowsProcess.Name            = process.ProcessName;
                    windowsProcess.StartTime       = process.StartTime;
                    windowsProcess.PagedMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.PagedMemorySize64
                    };
                    windowsProcess.NonPagedMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.NonpagedSystemMemorySize64
                    };
                    windowsProcess.VirtualMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.VirtualMemorySize64
                    };
                    windowsProcess.MemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.WorkingSet64
                    };
                    windowsProcess.PeakMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.PeakWorkingSet64
                    };
                    windowsProcess.TotalProcessorTime  = process.TotalProcessorTime;
                    windowsProcess.PeakPagedMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.PeakPagedMemorySize64
                    };
                    windowsProcess.PeakVirtualMemorySize = new UnitLongValue()
                    {
                        Unit = Unit.B, Value = process.PeakVirtualMemorySize64
                    };
                    windowsProcess.SessionId = process.SessionId.ToString();

                    var processOwner = this.GetProcessOwner(process);
                    windowsProcess.UserName = processOwner.Contains(@"\") ? processOwner.Substring(processOwner.IndexOf(@"\") + 1) : processOwner;

                    windowsProcesses.Add(windowsProcess);
                }
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex.Message, ex);
            }

            return(windowsProcesses);
        }
コード例 #2
0
        public static string GetCommandLine(System.Diagnostics.Process process)
        {
            if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
            {
                return(UnixProcess.GetCommandLine(process));
            }

            return(WindowsProcess.GetCommandLine(process));
        } // End Function GetCommandLine
コード例 #3
0
        } // End Function GetCommandLine

        public static void KillProcessAndChildren(int pid)
        {
            if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
            {
                UnixProcess.KillProcessAndChildren(pid);
            }
            else
            {
                WindowsProcess.KillProcessAndChildren(pid);
            }
        } // End Sub KillProcessAndChildren
コード例 #4
0
        protected override void Run()
        {
            Process = new WindowsProcess(ProcessName);

            var process = Process.GetProcess();

            if (process != null)
            {
                GameBot.Process = Process;
                GameBot.Window  = Process.GetWindow();
                GameBot.Window.Update();

                Publish(new GameLoaded());
            }
        }
コード例 #5
0
 public void Start(string[] args, ServiceOption option)
 {
     _serviceOption = option ?? throw new ArgumentNullException(nameof(option));
     _logService.Debug($"Service Name:{_serviceOption.ServiceName} Start");
     try
     {
         var childProc = Path.Combine(AppContext.BaseDirectory, "SampleWinFormsApp.exe");
         var processId = WindowsProcess.Start(childProc, "YanZh", true);
         _logService.Info($"Start SampleWinFormsApp.exe ==>{processId}");
     }
     catch (Win32ErrorCodeException ex)
     {
         _logService.Error($"{ex.Message}==》{ex.Win32ErrorCode}", ex);
     }
     catch (Exception ex)
     {
         _logService.Error($"{ex.Message}", ex);
     }
 }
コード例 #6
0
    public static IPlatformProcess BuildLauncherProcess()
    {
        WindowsProcess windowsProcess = new WindowsProcess();
        string         keyName        = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Disney Interactive\\Club Penguin Island Launcher";
        string         keyName2       = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Disney Interactive\\Club Penguin Island Launcher";
        object         value          = Registry.GetValue(keyName, "InstallPath", null);

        if (value == null)
        {
            value = Registry.GetValue(keyName2, "InstallPath", null);
        }
        windowsProcess.workingDirectory = (string)value;
        value = Registry.GetValue(keyName, "InstallExePath", null);
        if (value == null)
        {
            value = Registry.GetValue(keyName2, "InstallExePath", null);
        }
        windowsProcess.executableFilename = (string)value;
        return(windowsProcess);
    }
コード例 #7
0
        public static IEnumerable <IWindow> GetAllWindows(string processName)
        {
            if (String.IsNullOrWhiteSpace(processName))
            {
                throw new ArgumentException(nameof(processName));
            }

            string processNameSanitized = Path.GetFileNameWithoutExtension(processName);

            Process[] processInstances     = Process.GetProcessesByName(processNameSanitized);
            var       processWindowHandles = new List <IntPtr>();

            foreach (var instance in processInstances)
            {
                processWindowHandles.AddRange(runningWindows
                    ? WindowsProcess.GetRootWindowHandles(instance.Id)
                    : LinuxProcess.GetRootWindowHandles(instance.Id));
            }

            return(WindowFactory.CreateMultiple(processWindowHandles));
        }
コード例 #8
0
 public static IPlatformProcess BuildClientProcess()
 {
     return(WindowsProcess.BuildClientProcess());
 }
コード例 #9
0
 public static IPlatformProcess BuildLauncherProcess()
 {
     return(WindowsProcess.BuildLauncherProcess());
 }