windows 指定 exe 为服务

windows 指定任意 exe 为服务

sc.exe create ToolBox binPath= "D:\code\dotnet\ToolBox\ToolBox\bin\Debug\net8.0\ToolBox.exe"

sc.exe description ToolBox "提供本地 Web API 服务, 比如记账、日记、统计等等"

sc.exe config ToolBox start= auto

sc.exe start ToolBox

对应的 C# 代码也要改

// dotnet add package Microsoft.Extensions.Hosting.WindowsServices
if (OperatingSystem.IsWindows())
{
    builder.Host.UseWindowsService();
}

if (OperatingSystem.IsLinux())
{
    builder.Host.UseSystemd();
}

posted @ 2026-06-28 19:57  whmmm  阅读(7)  评论(0)    收藏  举报
//增加一段JS脚本,为目录生成使用