Archive: nsExec and SC.exe syntax problem


nsExec and SC.exe syntax problem
I am trying to start the service "Apache Tomcat 4.1" under Windows 2003.

The following worked for services with no spaces in their name, but it fails for Tomcat.

Worked:
nsExec::Exec '"$COMSPEC" /C ("sc" config myService obj= .\$U password= $P)'

Failed:
nsExec::Exec '"$COMSPEC" /C ("sc" config "Apache Tomcat 4.1" obj= .\$U password= $P)'

Any suggestions about this spaces problem?
Thanks,
Thierry


What are the parenthesis for? Why use $COMSPEC? sc.exe is an executable, not an internal command. If it doesn't work without those two, how about trying one of the other solutions?


The COMSPEC might not be needed, but it was an attempt to understand some strange differences between two W2K3 boxes. On one of them $SYSDIR\sc.exe was not found by nsExec, although sc was present in this directory. (I had the same problem with cscript. Sometimes the full path worked, sometimes calling only "sc" or "cscript" worked. I looked at the PATH without finding issues there).

The parenthesis are there to help with too many levels of quotes. Otherwise I would have written something like:

'"$COMSPEC" /C ""sc" config "Apache Tomcat 4.1" obj= .\$U password= $P"'
Right now the above works (the parenthesis version) if it is encapsualted in a .bat file and nsExec calls this .bat

It does not work when I directly call it from nsExec.

Other libraries could be used, but sc looked so simple.

Encapsulating in a .bat is a workable solution.

Thierry