Search code examples
windowscommand-lineservicesyntax

Proper quoted string syntax for change to Windows service Binpath needed


I have nearly the same issue as this poster here: How to pass double quoted string to sc.exe for binPath

But I didn't want to piggyback on a thread. I have a MySQL service that has not just an executable, but argument options in its binpath. I need to know how to format my quoted strings right to change the service, as I'm migrating a specific configuration from one server to another. Also, I'm doing a MySQL upgrade to a new version as part of the migration, so I can't just export the old registry key for the service as the primary paths don't match.

Original setup service binpath (let's call the service "MySQLd", I've sanitized this because its a specific application) using database MyDatabaseInstance :

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" MyDatabaseInstance

I need it to be like this:

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="D:\Database\my.ini" MyDatabaseInstance

I've tried a few options but I can't quite get there. Thanks everyone for your assistance.

I've gotten it halfway there:

sc.exe config MySQLd binPath= "\"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe\" --defaults-file="D:\Database\my.ini" MyDatabaseInstance

This fixes the first half, but leaves the quotes out of "D:\Database\my.ini" .


Solution

  • you must also encapsulate the second double quotes

    sc.exe config MySQLd binPath= "\"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe\" --defaults-file=\"D:\Database\my.ini\" MyDatabaseInstance"