Note: Wrapping a Program as a Windows Service with NSSM

Published on

Original language: Chinese . AI translations: English , Japanese .


I tinkered with V2Ray, and after finishing, I wanted to try using it without a GUI.

Goal: start wv2ray.exe automatically on boot, and be able to control it via the command line.

I looked around and found you can wrap a program as a service.

Steps:

  • Download nssm https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip
  • Open cmd in the folder where nssm.exe is located, and run nssm install v2ray
    • nssm install service_name: since you’ll type this service_name often, keep it short. I used v2ray, so nssm install v2ray is fine.
    • I used to do Windows + R -> cmd, then cd to the target dir. Later I learned you can type cmd directly in the folder address bar…
  • In the popup, set the path to wv2ray.exe, then click install service
  • Win + R -> services.msc, find the service you just registered, set it to auto-start, and start it
    • 2019/12/18 update
      You can choose the startup type in the second tab of the program. Pick as needed.
  • Now V2Ray can start on boot
  • Common commands
    • sc query v2ray check status
    • sc stop v2ray stop V2Ray (admin required)
    • sc start v2ray start V2Ray (admin required)

References:
使用nssm将cmd命令或.exe执行文件封装成Windows服务
NSSM - the Non-Sucking Service Manager - Usage
Windows 10 封装普通EXE为系统服务


When using V2Ray, Google Drive Sync can’t go through the proxy the way it did with SSR. I still don’t know how to fix it.
请问关于电脑应用走v2ray代理的问题(谷歌同步软件googledrivesync)