您的位置:首页 > 编程语言 > Go语言

Golang 编写msi,并在windows中注册为服务

2017-12-12 19:51 316 查看
Golang
编写msi,并在windows中注册为服务

这里注意:golang正常的写法,不需要添加任何操作。但是注册windows服务时不能使用sc命令,sc命令需要golang返回信息给sc,这里会报错。
1、编译成msi需要包,安装release版本,go-msi
https://github.com/mh-cbon/go-msi

2、下载安装wix
http://wixtoolset.org/releases/
安装完wix之后添加wix的bin目录到环境变量path
3、注册环境变量需要使用nssm,下载nssm到项目目录下,在下面配置文件中会用到http://nssm.cc/download
3、在golang编译好的exe下,放go-msi配置文件wix.json
 
{
  "product":"getmacaddress",
  "company": "mh-cbon",
  "upgrade-code":"db86ffd8-a4a2-4c4d-8140-c31ff42c9cf7",
  "files": {
    "guid":"35f3909c-e059-4c2b-ad62-95f21db9c294",
    "items": [
      "go_build_server_go.exe"
    ]
  },
  "directories": [
    "nssm-2.24"
  ],
  "env": {
    "guid":"c67d8185-d2f8-4912-9081-6c8104a575db",
    "vars": [
      {
        "name": "some",
        "value": "value",
        "permanent": "no",
        "system": "no",
        "action": "set",
        "part": "last"
      }
    ]
  },
  "shortcuts": {
    "guid":"07411c15-e4c6-4153-b199-450c2e3199c6",
    "items": [
      {
        "name":"go_build_server_go",
        "description":"go_build_server_go web server",
        "target":"[INSTALLDIR]\\go_build_server_go.exe",
        "wdir":"INSTALLDIR",
        "arguments": "",
        "icon": ""
      }
    ]
  },
  "choco": {},
  "hooks": [
    {
      "command":"[INSTALLDIR]nssm-2.24\\win32\\nssm.exe install getmacaddress[INSTALLDIR]go_build_server_go.exe",
      "when": "install"
    },
    {
      "command": "sc.exe startgetmacaddress",
      "when": "install"
    },
    {
      "command": "sc.exe deletegetmacaddress",
      "when": "uninstall"
    }
  ]
}
4、在配置文件下运行:go-msiset-guid
5、go-msi make--msi your_program.msi --version 0.0.2会在项目文件夹下生成your_program.msi
6、msi文件安装目录下不能有空格
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  golang msi windows服务