Undesired quotes when echoing variable input to hosts file

2 posts · Closed

rmpf2 Guest
25 Feb 2019

The following statement

%PsExec_VAR -h \\%0 cmd /c echo 10.0.64.185 some_name.com >> \\%0\c$\Windows\System32\drivers\etc\hosts

posts the results in hosts file

10.0.64.185 some_name.com
%PsExec_VAR -h \\%0 cmd /c echo {Enter ip host info:10.0.64.185 some_name.com} >> \\%0\c$\Windows\System32\drivers\etc\hosts

causes undesired output quotes:

"10.0.64.185 some_name.com"

Any idea how to avoid those quotes? (Dequote - Remove Quotes from a string)

Andrew SoftPerfect
26 Feb 2019

The quotes are added because there is a space, meaning the string has to be enquoted into a single parameter.

In your case there may be an easy workaround:

  1. Open Notepad and hit Tab. Then copy that tab character.
  2. Insert the copied tab between the strings like this:
    ... cmd /c echo 10.0.64.185[color=#FF0000]tab[/color]some_name.com >> ...
  3. The tab-separated string should be echoed unquoted and written to the file.

By the way, I don't quite understand why you are using psexec to execute the command remotely and then pass the same IP address in path. It looks like either of the following will also work:

cmd /c echo {Enter ip host info:10.0.64.185[color=#FF0000]tab[/color]some_name.com} >> \\%0\c$\Windows\System32\drivers\etc\hosts

or

%PsExec_VAR -h \\%0 cmd /c echo {Enter ip host info:10.0.64.185[color=#FF0000]tab[/color]some_name.com} >> C:\Windows\System32\drivers\etc\hosts
This topic is closed. It has had no new posts for over a year, so the software versions it talks about may be out of date. Start a new topic in Network Scanner if you have a similar question.