prashanthkr08
prashanthkr08

Reputation: 75

Batch file Error : "Files was unexpected at this time."

I am getting the below error when I pass path as my 2nd argument. It looks like problem is with the space.

Files was unexpected at this time

I am executing the batch file with 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

Upvotes: 3

Views: 25446

Answers (3)

Mohammad Kanan
Mohammad Kanan

Reputation: 4582

I Just changed to useing ' instead of " ,

if NOT '%1' == '' SET var1=%1
if NOT '%2' == '' SET var2=%2
if NOT '%3' == '' SET var3=%3

Ang got it working without the error, not sure if related to parameter expansion , as I am not using parenthesis

Upvotes: 0

foxidrive
foxidrive

Reputation: 41234

As well as Dave's comment, you need tildas 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 for all four parameters (if all 4 are required) is this:

if "%~4" == "" goto PARAMS

Upvotes: 3

dbenham
dbenham

Reputation: 130819

You cannot escape quotes within a quoted string. Use %~2 to get rid of the unwanted quotes from a parameter.

Try the following:

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

Upvotes: 4

Related Questions