Running SC from command line

215 views Asked by At

I have the following work in progress:

    @ECHO OFF
SET SERVICE_NAME=VBoxService
if [%VBOX_EXE%] == [] (
  SET VBOX_EXE="D:\Program Files\Oracle\VirtualBox\VBoxWebSrv.exe"
)
ECHO VBOX_EXE set to %VBOX_EXE%

IF [%1]==[] (
  ECHO Missing parameter
  GOTO USAGE
)

IF "%1" == "install" GOTO INSTALL
IF "%1" == "remove" GOTO REMOVE
ECHO Invalid parameter
GOTO USAGE

:INSTALL
ECHO Installing %SERVICE_NAME% service
echo SC CREATE %SERVICE_NAME% binPath= %VBOX_EXE%
GOTO END

:REMOVE
ECHO Uninstalling %SERVICE_NAME% service
SC DELETE %SERVICE_NAME%
GOTO END


:USAGE
ECHO Usage:
ECHO %0 "[install]|[remove]"
ECHO if environtment variable VBOX_EXE is not set it will be set to:
ECHO   "D:\Program Files\Oracle\VirtualBox\VBoxWebSrv.exe"
ECHO Where install installs the service
ECHO and remove removes the service

:END

The problem I am having is the call to SC CREATE is not working right. The command looks good, if I copy/past it from the command window, it works as expected, but when run from the batch file it never creates the service. I have a feeling it is a quoting issue.

thanks in advance

1

There are 1 answers

0
jordanthompson On

Duh... I was debugging and forgot to remove the echo from the line. Once I removed the echo, everything works as planned.