How to escape comma in wmic?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rodrigo.brasil
Posts: 10
Joined: 20 Jun 2023 16:15

How to escape comma in wmic?

#1 Post by rodrigo.brasil » 20 Jun 2023 16:41

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.

ohenryx2
Posts: 5
Joined: 08 Apr 2023 14:16

Re: How to escape comma in wmic?

#2 Post by ohenryx2 » 24 Jun 2023 19:06

Okay, I'm curious. What exactly is the point of all this? Why are you using wmic to simply run cmd.exe ?

rodrigo.brasil
Posts: 10
Joined: 20 Jun 2023 16:15

Re: How to escape comma in wmic?

#3 Post by rodrigo.brasil » 24 Jun 2023 21:18

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.

rodrigo.brasil
Posts: 10
Joined: 20 Jun 2023 16:15

Re: How to escape comma in wmic?

#4 Post by rodrigo.brasil » 25 Jun 2023 14:13

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

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: How to escape comma in wmic?

#5 Post by miskox » 27 Jun 2023 10:11

Very good idea! Congratulations!

Saso

lazna
Posts: 54
Joined: 27 Dec 2012 10:54

Re: How to escape comma in wmic?

#6 Post by lazna » 02 Jul 2023 12:45

just FYI: wmic is obsolette

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to escape comma in wmic?

#7 Post by ShadowThief » 02 Jul 2023 15:54

lazna wrote:
02 Jul 2023 12:45
just FYI: wmic is obsolette
no it isn't

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How to escape comma in wmic?

#8 Post by npocmaka_ » 02 Jul 2023 16:04

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.

lazna
Posts: 54
Joined: 27 Dec 2012 10:54

Re: How to escape comma in wmic?

#9 Post by lazna » 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

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to escape comma in wmic?

#10 Post by ShadowThief » 03 Jul 2023 10:16

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.

lazna
Posts: 54
Joined: 27 Dec 2012 10:54

Re: How to escape comma in wmic?

#11 Post by lazna » 03 Jul 2023 10:51

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

Post Reply