Files
Obsidian/MyBestNanobot/nanobot 在 Windows 作为系统服务运行.md
2026-07-21 14:53:24 +08:00

82 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
好问题!nanobot 在 Windows 上主要有两种方式实现开机自启,推荐用 **任务计划程序**(最简单,无需额外工具)或 **NSSM**(真正的系统服务)。
先确认启动命令——从状态看,你用的是 `nanobot gateway`:
---
## 方式一:任务计划程序(推荐,最简单)
无需装任何东西,开机登录时自动启动:
**1. 按 `Win + R`,输入 `taskschd.msc` 打开任务计划程序**
**2. 右侧点击「创建任务」**
**3. 配置如下:**
| 选项卡 | 设置 |
|--------|------|
| **常规** | 名称:`nanobot`<br>勾选「使用最高权限运行」<br>选择「不管用户是否登录都要运行」(或「只在用户登录时运行」) |
| **触发器** | 新建 → 开始任务:**启动时**(或**登录时**) |
| **操作** | 新建 → 操作:**启动程序**<br>程序或脚本:`C:\Users\niaod\.local\bin\nanobot.exe`<br>添加参数:`gateway`<br>起始于(可选):`C:\Users\niaod\.nanobot\workspace` |
| **条件** | 取消勾选「只有在计算机使用交流电源时才启动此任务」 |
| **设置** | 勾选「如果任务失败,按以下频率重启」设为 1 分钟<br>「允许按需运行任务」 |
**4. 确定后输入 Windows 密码即可。**
> ✅ 优点是零依赖,支持重启、日志记录。缺点是只在用户登录后才启动。
---
## 方式二:NSSM — 包装为真正的 Windows 系统服务
如果你想要一个在系统启动时(**甚至在登录前**)就运行、后台常驻、不弹出窗口的真 · 服务:
### 1️⃣ 下载 NSSM
```powershell
winget install nssm
# 或手动下载:https://nssm.cc/download
```
### 2️⃣ 创建服务
```powershell
# 管理员 PowerShell
nssm install nanobot
```
在弹出的 GUI 窗口中设置:
- **Application** → Path: `C:\Users\niaod\.local\bin\nanobot.exe`
- **Application** → Arguments: `gateway`
- **Startup directory**: `C:\Users\niaod\.nanobot\workspace`
- **Details** → Display name: `nanobot AI Assistant`
- **Details** → Startup type: **Automatic**
点 Install Service,搞定。
### 管理命令
```powershell
nssm start nanobot # 启动服务
nssm stop nanobot # 停止
nssm restart nanobot # 重启
nssm edit nanobot # 修改配置
```
---
## 方式三:开机启动文件夹(最简但最弱)
```powershell
# Win+R → shell:startup
# 创建一个快捷方式:
目标: C:\Users\niaod\.local\bin\nanobot.exe gateway
```
缺点是会有命令行窗口,而且没有自动重启。
---
**我建议你用方式一(任务计划程序)**,零安装、带重启策略、足够稳定。你目前用的是 `gateway` 还是 `serve` 命令?