-1

When using this command in my batch script the set command is interpreted as the default windows batch "set an environment command":

@echo off
echo "Always run this script as Administrator. If you don't the service will be installed but not correctly configured!"

set serviceName=MyApp
set serviceLabel=MyApp
set serviceExe=MyApp.exe

set maindir=C:\\Users\\MyUser\\Desktop\\MyApp\\
set nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe

%nssm% install %serviceName% "%maindir%\\%serviceExe%"

How do I prevent this?

Compo
  • 36,585
  • 5
  • 27
  • 39
FabianTe
  • 516
  • 4
  • 22
  • Now that you've modified your code, did you notice that `%nssm%` has a value of `C:\\Users\\MyUser\\Desktop\\MyApp\\\\lib\\nssm-2.24\\win64\\nssm.exe`? I would suggest that is your issue! _Windows uses a single back slash as it's path separator_. It also shows that you should be using either, `"%maindir%%serviceExe%"` or `maindir=C:\\Users\\MyUser\\Desktop\\MyApp`. Additionally, I would recommend that you use this syntax, `Set "VariableName=StringValue"`. – Compo Jul 15 '19 at 10:32
  • Okay, will do. Thank you. I do realize that I should properly learn batch scripting. – FabianTe Jul 15 '19 at 10:41

2 Answers2

1

An example, based upon my comment:

@Echo Off
Set "serviceName=MyApp"
Set "serviceExe=MyApp.exe"
Set "maindir=C:\\Users\\MyUser\\Desktop\\MyApp"
Set "nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe"

"%nssm:\\=\%" install %serviceName% "%maindir%\\%serviceExe%"
Compo
  • 36,585
  • 5
  • 27
  • 39
0

Figured it out:

In my original script i had the nssm exe as a variable:

%nssm% set %serviceName% AppDirectory "%maindir%"

Somehow this confuses the script.

Just use an actual path to nssm.exe and it works:

.\nssm.exe set %serviceName% AppDirectory "%maindir%"
FabianTe
  • 516
  • 4
  • 22
  • Sorry, I admit I didn't supply the correct example as I was in a hurry. In my edit I added the actual script I was using before. In that I have replaced the variable `nssm` with the path to the actual executable and it now works. – FabianTe Jul 15 '19 at 10:01