Files
cftunnel/internal/service/windows.go
T
晴天 a7e4cf9dff feat: 全面支持 Windows 平台 + 修复 macOS tgz 解压 bug
- goreleaser 添加 windows 构建(zip 格式)
- cloudflared 下载支持 Windows + macOS tgz 解压
- 进程管理跨平台(process_unix/process_windows)
- 信号处理跨平台(signal_unix/signal_windows)
- Windows Service 实现(sc.exe)
- selfupdate 支持 Windows zip 格式
- PowerShell 安装脚本
- README 添加 Windows 安装说明
2026-02-23 01:20:18 +08:00

39 lines
827 B
Go

//go:build windows
package service
import (
"fmt"
"os/exec"
"strings"
)
type Windows struct{}
const svcName = "cftunnel"
func (w *Windows) Install(binPath, token string) error {
binArg := fmt.Sprintf(`%s tunnel run --token %s`, binPath, token)
if err := exec.Command("sc", "create", svcName, "binPath=", binArg, "start=", "auto").Run(); err != nil {
return fmt.Errorf("创建服务失败: %w", err)
}
return exec.Command("sc", "start", svcName).Run()
}
func (w *Windows) Uninstall() error {
exec.Command("sc", "stop", svcName).Run()
return exec.Command("sc", "delete", svcName).Run()
}
func (w *Windows) Running() bool {
out, err := exec.Command("sc", "query", svcName).Output()
if err != nil {
return false
}
return strings.Contains(string(out), "RUNNING")
}
func New() Service {
return &Windows{}
}