Welcome!

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

SignUp Now!

tcommand(cmd)

Aug
2,059
83
From What's New in Version 21:
You can also now call TCC via a COM interface (in TakeCmd.tlb) from scripts. The "tcommand(cmd)" function will execute any internal TCC command.

I have searched the entire help file, and this is the only reference I can find to tcommand(cmd).

It would be appreciated if someone could post working code showing how to use the tcommand(cmd), preferably using the VBScript Active Scripting Engine.

Thanks from Joe
 
TCC adds its COM interface to the script engine you're invoking.
Can you give a working example? This doesn't work.
Code:
v:\> type test.vbs
tcommand(dir)

v:\> script /e VBScript test.vbs

---------------------------
Script Error
---------------------------
Type mismatch: 'tcommand' - (0:0)
---------------------------
OK   
---------------------------
 
Does that mean it is accessible only to script engines being instantiated by TCC? (making TCC an in-process server only)

Does the TCC instance implementing the interface share the same environment and internal state as the instance which invoked a script being run by an Active Scripting engine?

It would be useful to see an example of instantiating the TCC provider of the TCC_Scripting_1 interface.

Could you say what is wrong with the following, when named silly.vbs and run via
cscript //Nologo silly.vbs
from a TCC v23 shell?
Code:
' .vbs script attempting to use TCC as a COM server
Wscript.Echo "Attempting TCC server instantiation ..."

Dim oTcc

On Error Resume Next

Set oTcc = Wscript.CreateObject("TCC_1_0.TCC_Scripting_1")
If IsObject(oTcc) Then
   Wscript.Echo "Success! Now, make the server do something."
   oTcc.tcommand("touch /c %TEMP%\tcc_automation_was_here.tmp")
   Set oTcc = Nothing
else
   Wscript.Echo "Could not instantiate TCC server."
   Wscript.Echo "Error: ", Err.Description
end if

The output is:
Code:
Attempting TCC server instantiation ...
Could not instantiate TCC server.
Error:  Could not locate automation class named "TCC_1_0.TCC_Scripting_1".
 
I couldn't find "TCC_1_0" in the registry.

AFAICT, no TCC-related object classes show up in OLEVIEW.EXE.

Three TypeLib's show up in OLEVIEW.EXE.
Code:
g:\tc23> regdir /d /v HKCR\TypeLib\{0474E6A3-6F13-4EE3-88F6-3E7E36367761}
HKCR\TypeLib\{0474E6A3-6F13-4EE3-88F6-3E7E36367761}
  15.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\TC21\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\TC21
  16.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\tc22\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\tc22
  17.0
     : REG_SZ : TCC Automation Interfaces
    0
      win32
         : REG_SZ : G:\tc23\TakeCmd.tlb
    FLAGS
       : REG_SZ : 0
    HELPDIR
       : REG_SZ : G:\tc23
 
I used Visual Studio 2017's object viewer to open TakeCmd.tlb directly.

None of the DLLs had the entry point(s) needed for regsvr32 to get them to register as an in-proc or out-of-proc server.

I have been completely unable to unearth any evidence that running scripts under TCC's script command can get an interface to TCC. (I'm not saying there is no way; just that I find no docs and my trial and error process has been all error.) However, I will give it some more trials using the CLSID's Vince found.

The tcommand method returns nothing. This makes me wonder if it is intended to be a useful feature.
 
Can you elaborate some?
1532803826459.png
 
OK, it works when I use the SCRIPT command. Is there anything about this in the help?
 
I'm having trouble with VBScript and SCRIPT. Please see the "About scripting?" thread.
 
What about PerlScript? Below, I see no indication at all that the script has anything past the "printf" line.

Code:
v:\> type test.pls
$a = "First Message";
$b = "echo Second Message";
$c = "dir /w";
printf("%s\n%s\n%s\n", $a, $b, $c);
TakeCommand.msgbox($a);
TakeCommand.tcommand($b);
TakeCommand.tcommand($c);
TakeCommand.garbage(trash);
garbage.trash(foo);

v:\> script test.pls
First Message
echo Second Message
dir /w

v:\>
 
I have had no luck using PerlScript. Croaking errors seem to be trapped and silenced.

When the following is run, $Count is 0, meaning no objects appear to be live. The GetActiveObject call does return an undef. (I'm still mystified as to whether TCC has given the scripting engine an interface to its host. It seems not.)

Code:
use Win32::OLE;
$c = "dir /w";
Win32::OLE->Initialize(Win32::OLE::COINIT_APARTMENTTHREADED);
$Count = Win32::OLE->EnumAllObjects(sub {
   my $Object = shift;
   my $Class = Win32::OLE->QueryObjectType($Object);
   printf "# Object=%s Class=%s\n", $Object, $Class;
});
print $Count, "?\n";

my $tc = Win32::OLE->GetActiveObject('TakeCommand');

if (defined($tc) && $tc != 0) { print "Hooray\n"; }
elsif (!defined($tc)) { print "Rats\n"; }
else { print "Failure trapped\n"; }

#$tc->tcommand($c);

One interesting answer to my earlier question:
This code,
Code:
var d3 = "set Poodles=Pepe,Fifi";
TakeCommand.tcommand(d3);
does appear to set an environment variable in the TCC host when the code is run as JScript using TCC's 'script' command.

It would be great if the tcommand method or an alternate for it returned error status.
 
Back
Top
[FOX] Ultimate Translator
Translate