Sage.WindowsProcess 1.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sage.WindowsProcess --version 1.0.0.1
                    
NuGet\Install-Package Sage.WindowsProcess -Version 1.0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sage.WindowsProcess" Version="1.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sage.WindowsProcess" Version="1.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Sage.WindowsProcess" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sage.WindowsProcess --version 1.0.0.1
                    
#r "nuget: Sage.WindowsProcess, 1.0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sage.WindowsProcess@1.0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sage.WindowsProcess&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Sage.WindowsProcess&version=1.0.0.1
                    
Install as a Cake Tool

Sage.WindowsProcess

简介

Sage.WindowsProcess 提供了 Windows 进程管理功能,包括启动、停止、监控和资源管理,提供了开机启动(windows)和获取调用父进程信息的功能。

主要特性

  • 进程生命周期管理
  • 进程监控(CPU、内存使用率等)
  • 获取进程输出和错误信息(重定向)
  • 自动重启进程功能
  • 开机启动程序
  • 获取父进程信息(cmd shell 等)
  • 完全兼容 AOT 编译

使用示例

using Sage.WindowsProcess.Services;
using Sage.WindowsProcess.Configuration;
using Sage.WindowsProcess.Events;
using Sage.WindowsProcess.Models;

// 创建进程配置
var config = new ProcessConfig
{
    Key = "notepad",
    ExecutablePath = "notepad.exe",
    Arguments = "example.txt",
    WorkingDirectory = Environment.CurrentDirectory,
    AutoRestart = true,
    MaxRestartAttempts = 3
};

// 创建进程管理服务
var processManager = new ProcessManagerService(new[] { 
config });

// 注册事件处理
processManager.ProcessStarted += (sender, e) =>
{
    Console.WriteLine($"进程已启动:{e.ProcessKey}, 
    PID: {e.ProcessId}");
};

processManager.ProcessStopped += (sender, e) =>
{
    Console.WriteLine($"进程已停止:{e.ProcessKey}, 退出
    代码: {e.ExitCode}");
};

processManager.ProcessOutput += (sender, e) =>
{
    Console.WriteLine($"[{e.ProcessKey}] {e.Data}");
};

// 启动进程
await processManager.StartProcessAsync("notepad");

// 获取进程状态
var status = processManager.GetProcessStatus
("notepad");
Console.WriteLine($"进程状态:{status.State}, CPU: 
{status.CpuUsage}%, 内存: {status.MemoryUsageMB}MB");

// 停止进程
await processManager.StopProcessAsync("notepad");

// 释放资源
await processManager.DisposeAsync();

// 获取父进程信息
class Program
{
    static void Main(string[] args)
    {
        // 获取父进程完整信息
        var parentInfo = ProcessParentInfo.ParentProcessUtility.GetParentProcessInfo();
        
        // 检查信息是否有效
        if (parentInfo.IsValid())
        {
            Console.WriteLine($"父进程ID: {parentInfo.Id}");
            Console.WriteLine($"父进程名称: {parentInfo.Name}");
            Console.WriteLine($"父进程路径: {parentInfo.Path}");
        }
        else
        {
            Console.WriteLine("无法获取有效的父进程信息");
        }
    }
}

许可证

版权所有 © 2025 甲壳虫科技 团队。

贡献

欢迎提交问题和功能请求。 QQ Group: 1054304346

作者

甲壳虫科技

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.8 60 10/2/2025
1.0.0.7 170 9/23/2025
1.0.0.6 157 8/20/2025
1.0.0.5 165 8/20/2025
1.0.0.4 164 8/20/2025
1.0.0.3 146 8/19/2025
1.0.0.2 159 8/19/2025
1.0.0.1 158 8/19/2025
1.0.0 146 7/16/2025

新增了父进程信息获取,用于当程序被调用(cmd shell 等)时候获取父进程信息。