Batch file error: "Files were unexpected at present."

I get the error below when I pass pathas the second argument. The problem seems to be related to space.

Files was unexpected at this time

I am executing a batch file with the following parameters

services.cmd 2 "C:\Program Files (x86)\folder\Folder\folder\Bin" corp\acct password

CODE:

@echo off

if "%1" == "" goto PARAMS
if "%2" == "" goto PARAMS
if "%3" == "" goto PARAMS
if "%4" == "" goto PARAMS


sc create "<service name>"%1 binpath= "\%2\xxx.exe\" \"xxx.exe.config\""
rem sc config "<service name>"%1 displayname= "<display name>"%1 obj= %3 password= %4 start= auto description= "Runs the service."


goto END

:PARAMS

echo Usage CreateServices.cmd binfoldername binfolderpath username password

:END
+3
source share
2 answers

You cannot escape the quotation marks in the quoted string. Use %~2to get rid of unwanted quotation marks from a parameter.

Try the following:

sc create "<service name>%~1" binpath= "%~2\xxx.exe" "xxx.exe.config"
+4
source

Like Dave's comment, you need tildes in these lines

if "%~1" == "" goto PARAMS
if "%~2" == "" goto PARAMS
if "%~3" == "" goto PARAMS
if "%~4" == "" goto PARAMS

But all you need to check all four parameters (if all 4 are required) is:

if "%~4" == "" goto PARAMS
+3
source

All Articles