Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

FOR usage error from TCC but not from CMD

Oct
15
0
I'm having a hard time figuring out why TCC is not accepting a FOR command that CMD is accepting and working as expected.

I am trying to use WMIC to get the version of a file. The following works when run with CMD.

Code:
FOR /F "tokens=2 delims==" %%I IN ('wmic datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get version /format:list') DO SET "RESULT=%%I"

ECHO %RESULT%

When this is run with TCC I get this:

Code:
test.cmd [10]  Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /Nj /O:[-]adegnrstu /R [path] /T"..." /W] %var IN ([@]set | start, step, end) [DO] command ...

I am not understanding what the issue is and would appreciate any help.
 
I think this has something to do with the single quotes around the wmic command. When this is removed CMD will fail with The system cannot find the file wmic.

I just cannot figure out how TCC wants this formated.
 
I think I figured out how to work around this.

Code:
wmic datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get version /format:list | for /f "tokens=2 delims==" %%I in (@CON:) DO ECHO %%I
 
Can't help you with FOR -- but when I want to snarf the output of a command, I use %@EXECSTR. (If the object of the game is to get the file's version number, it might be a lot easier to use %@FILEVER instead of calling an external.)
 
I really appreciate the help.

%@EXECSTR gives me "ECHO is OFF" which is common with wmic because of all of the garbage that it spits out.
I cannot find %@FILEVER in the help file, only %@VERINFO. This may work however, I need to run this on a remote system. I am checking the version of a program as part of an upgrade script. I just figured it would be easier to provide a local file check as an example.

Is there a way to direct TCC to execute the FOR command in "CMD mode" then switch back to TCC mode?

To add to the confusion, this gives me nothing:
WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value /format:csv | for /f "skip=2 tokens=2 delims=," %a in (@CON:) do (set VER=%a)

While this gives me the version of the file:
WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value /format:csv | for /f "skip=2 tokens=2 delims=," %a in (@CON:) do (ECHO %a)

Why can't I just assign the value to a variable? sigh
 
Hi @rmoody ,

Try this;
Code:
c:\users\jlc\utils>echo %@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]
Version=7.6.4.0

To assign the value to a variable;
Code:
c:\users\jlc\utils>set theVersion=%@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]

c:\users\jlc\utils>echo %theVersion
Version=7.6.4.0

c:\program files\notepad++>echo %@word["=",-0,%theVersion]
7.6.4.0

Joe
 
Last edited:
Must you use FOR? In TCC you can ...

Code:
v:\> set notepad_version=%@wmi[root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]

v:\> echo %notepad_version
6.1.7600.16385
 
Hi @vefatica,
Interesting. My command line seems to give an incorrect result, while yours matches @verinfo;
Code:
c:\windows>echo %@verinfo[notepad.exe]
6.1.7600.16385 (win7_rtm.090713-1255)

Joe
 
Duh! Different program. My bad!
Code:
c:\program files\notepad++>echo %@verinfo[notepad++.exe]
7.64

Joe
 
Hi @rmoody ,

Try this;
Code:
c:\users\jlc\utils>echo %@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]
Version=7.6.4.0

To assign the value to a variable;
Code:
c:\users\jlc\utils>set theVersion=%@execstr[2,WMIC datafile where "name='C:\\Program Files\\Notepad++\\notepad++.exe'" get Version /value]

c:\users\jlc\utils>echo %theVersion
Version=7.6.4.0

c:\program files\notepad++>echo %@word["=",-0,%theVersion]
7.6.4.0

Joe

Thank you! This seems to work! Tested on a remote system like this:

set theVersion=%@execstr[2,WMIC /NODE:"systemname" datafile where "name='C:\\Program Files (x86)\\Notepad++\\notepad++.exe'" get Version /value]

I'm in no way attached to a FOR loop, it's just what I had found. I'll use whatever works, I'm all about the Perl moto: There's more than one way to do it.

vefatica: I could not figure out how to use @VERINFO to get the version of a file on a remote system.
 
vefatica: I could not figure out how to use @VERINFO to get the version of a file on a remote system.
This works.
Code:
v:\> echo %@verinfo[\\zz\c$\Windows\System32\notepad.exe]
6.1.7600.16385 (win7_rtm.090713-1255)
I'm pretty sure it will not work with a URL.
 
For what it's worth, WMI is pretty easy to use remotely (if the firewall allows it). Below, the only difference is the addition of "\\bb\" to the namespace parameter
Code:
v:\> echo %@wmi[root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]
6.1.7600.16385

v:\> echo %@wmi[\\bb\root\cimv2,"select version from CIM_datafile where name='c:\\windows\\system32\\notepad.exe'"]
10.0.18362.1
 
Just updated TCC and tested. The FOR command I was having issues with works now.

Thank you so much for fixing that and for such a great product (been using TCC off and on since the WFWG 3.11 days!)
 

Similar threads

Back
Top