0

This command works locally:

for /f "tokens=2" %s in ('sc query state^=inactive ^| find /i "SERVICE_NAME: work"') do set service=%s

But doesn't work when I try running it on this computer from another computer:

wmic /node:"<station_name>" process call create "cmd.exe /c for /f "tokens=2" %s in ('sc query state^=inactive ^| find /i "SERVICE_NAME: work"') do set service=%s"

I'm getting the following error:

Invalid named parameter list.
Hint: <named param list> ::= <named param> | <named param> <named param list> where <named param> ::= <param name>=<param value>

I've managed to run simple commands, like:

wmic /node:"<station_name>" process call create "cmd.exe /c echo hi > c:\test\output.log"

How do I run the previous command with wmic?

user2653179
  • 393
  • 1
  • 6
  • 21
  • Does this answer your question? [Escaping strings when using wmic](https://stackoverflow.com/questions/23827199/escaping-strings-when-using-wmic) – JosefZ May 26 '21 at 19:51
  • 1
    Why are you using sc.exe and find.exe, run from a new cmd.exe process via WMIC.exe? You could probably do this much simpler using just WMIC and the Win32_Service class: `WMIC.exe /Node:"" Service Where "State='Stopped' And Name Like '%work%'" Get Name /Format:List` – Compo May 27 '21 at 09:53
  • 1
    I would appreciate it if you provided appropriate feedback, _(since you've logged in today, and still ignored the above comment.)_ BTW to also output to a file you could extend that too: `%SystemRoot%\System32\wbem\WMIC.exe /Node:"" /Output "C:\test\output.log" Service Where "State='Stopped' And Name Like '%work%'" Get Name /Format:List`. Obviously from a batch-file, that would change to: `@%SystemRoot%\System32\wbem\WMIC.exe /Node:"" /Output "C:\test\output.log" Service Where "State='Stopped' And Name Like '%%work%%'" Get Name /Format:List` – Compo May 28 '21 at 16:19
  • If you wanted to save the output to a variable for further use, you'd have to explain the circumstances better, for a more focused example. – Compo May 28 '21 at 16:23
  • Sorry for the late reply. The variable is needed to start the service using "net start . First I need to find the exact service name for it. – user2653179 Aug 22 '21 at 16:17

0 Answers0