@echo on setlocal enabledelayedexpansion REM 定义变量 set NGINX_DIR=%~dp0 set WORKDIR=%NGINX_DIR%nginx_data set NGINX_EXE=%NGINX_DIR%nginx.exe set CONFIG_FILE=%NGINX_DIR%nginx_data\conf\nginx.conf ::set CONFIG_FILE=%NGINX_DIR%..\..\..\web\windows10\nginx\conf\nginx.conf REM 停止和删除旧服务 %~dp0\nssm stop Nginx %~dp0\nssm remove Nginx confirm %~dp0\nssm install Nginx %NGINX_EXE% if not exist "%CONFIG_FILE%" ( echo config file not exist: %CONFIG_FILE% pause exit /b 1 ) %~dp0\nssm set Nginx DisplayName "Nginx service" %~dp0\nssm set Nginx Description "Nginx service installed by yuanxin with NSSM" %~dp0\nssm set Nginx Start SERVICE_AUTO_START %~dp0\nssm set Nginx AppParameters -c "%CONFIG_FILE%" %~dp0\nssm set Nginx AppDirectory "%WORKDIR%" %~dp0\nssm set Nginx AppStdout %~dp0Nginx_stdout.log %~dp0\nssm set Nginx AppStderr %~dp0Nginx_stderr.log %~dp0\nssm start Nginx reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path | findstr "%%NGINX_HOME%%" && goto :case1 || goto :case2 pause goto :eof :case1 echo "case1" setx /M NGINX_HOME "%WORKDIR%" goto :eof :case2 echo "case2" for /f "tokens=2*" %%I in ( 'reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path' ) do set "NGINXpath=%%J" setlocal enabledelayedexpansion wmic ENVIRONMENT where "name='path' and username=''" set VariableValue="!NGINXpath!;%%NGINX_HOME%%" setx /M NGINX_HOME "%WORKDIR%" goto :eof echo success! pause