Page 1 of 1

How to escape comma in wmic?

Posted: 20 Jun 2023 16:41
by rodrigo.brasil
This is making me crazy. I want to run a cmd inside wmic.

Code: Select all

wmic process call create 'cmd /c "echo hello wold >c:\test.txt" ' &timeout 1& type c:\test.txt
This command work well. (You need some delay to read the file). If I want to print all character from the keyboard, I can make this:

Code: Select all

wmic process call create 'cmd /c "echo start ""''!@#$%¨^&*()-_=+`´[{}]^^~^<^>.;:?/^|\ end >c:\test.txt" ' &timeout 1& type c:\test.txt
It will print:
start ""''!@#$%¨&*()-_=+`´[{}]^~<>.;:?/|\ end

Ok, a lot of problematic characters. Quote and double quote can only print two not one. But if i try ANY command with a comma:

Code: Select all

wmic process call create 'cmd /c "echo Please accept the comma, ARRRHHHH >c:\test.txt" ' &timeout 1& type c:\test.txt
It will faill :evil: :evil: :evil: !!!! There is no way to put comma! How to use a comma in the wmic process call create???

Ps:I don't want just print it, this is an example.

Re: How to escape comma in wmic?

Posted: 24 Jun 2023 19:06
by ohenryx2
Okay, I'm curious. What exactly is the point of all this? Why are you using wmic to simply run cmd.exe ?

Re: How to escape comma in wmic?

Posted: 24 Jun 2023 21:18
by rodrigo.brasil
Well, you can run commands remotely in another computer network. Just pass the user and password. I could not believe that I can't escape the comma. I build another strategy like to send the command in base64 and decode it.

Re: How to escape comma in wmic?

Posted: 25 Jun 2023 14:13
by rodrigo.brasil
I get new ideas! And finaly it worked!!!

Code: Select all

wmic process call create 'cmd /E:ON /V:ON /c "(cmd /c exit 44 ) & SET coma=!=exitcodeAscii!& echo Please accept the comma !coma! YESSSS!!!!! >c:\test.txt" ' &timeout 1& type c:\test.txt
Now I can run more complex commands:

Code: Select all

wmic process call create 'cmd /E:ON /V:ON /c "(cmd /c exit 44 ) & SET coma=!=exitcodeAscii!& SET comando=FOR /L %G IN (1!coma!1!coma!5) DO @echo %G & cmd /c !comando! >c:\test.txt" ' &timeout 1& type c:\test.txt

Re: How to escape comma in wmic?

Posted: 27 Jun 2023 10:11
by miskox
Very good idea! Congratulations!

Saso

Re: How to escape comma in wmic?

Posted: 02 Jul 2023 12:45
by lazna
just FYI: wmic is obsolette

Re: How to escape comma in wmic?

Posted: 02 Jul 2023 15:54
by ShadowThief
lazna wrote:
02 Jul 2023 12:45
just FYI: wmic is obsolette
no it isn't

Re: How to escape comma in wmic?

Posted: 02 Jul 2023 16:04
by npocmaka_
At the moment I'm using macbook (it's atrocious) and I cannot test it. Though for the where clause the escape symbol is backslash but I'm not sure if this will work for call but you can try it.

Re: How to escape comma in wmic?

Posted: 03 Jul 2023 03:02
by lazna
ShadowThief wrote:
02 Jul 2023 15:54
lazna wrote:
02 Jul 2023 12:45
just FYI: wmic is obsolette
no it isn't
Sorry for wrong word 'obsolette', wmic is deprecated

Re: How to escape comma in wmic?

Posted: 03 Jul 2023 10:16
by ShadowThief
lazna wrote:
03 Jul 2023 03:02
ShadowThief wrote:
02 Jul 2023 15:54
lazna wrote:
02 Jul 2023 12:45
just FYI: wmic is obsolette
no it isn't
Sorry for wrong word 'obsolette', wmic is deprecated
They removed the warning in Windows 11, so it's fair to say that it also isn't deprecated.

Re: How to escape comma in wmic?

Posted: 03 Jul 2023 10:51
by lazna
ShadowThief wrote:
03 Jul 2023 10:16
lazna wrote:
03 Jul 2023 03:02
ShadowThief wrote:
02 Jul 2023 15:54

no it isn't
Sorry for wrong word 'obsolette', wmic is deprecated
They removed the warning in Windows 11, so it's fair to say that it also isn't deprecated.
"The WMIC tool is deprecated in Windows 10, version 21H1 and the 21H1 General Availability Channel release of Windows Server. This tool is superseded by Windows PowerShell for WMI. Note: This deprecation only applies to the command-line management tool. WMI itself isn't affected."

https://learn.microsoft.com/en-us/windo ... d-features