Welcome!

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

SignUp Now!

Determine if a .vbs is running from SCRIPT or CSCRIPT

Aug
1,914
68
I wanted to know if I was running a .vbs (VBScript) file from either the TCC Script command, or CScript.exe.

The following .vbs (VBScript) file can be run from either the TCC Script command, or CScript.exe, to determine where the .vbs is running from.
Code:
' VbsEdit Toolkit is part of VBSEdit.

Set tk = CreateObject( "VbsEdit.Toolkit" )

PID = tk.CurrentProcessID
PIDModule = tk.ModuleFilenameFromProcessId(PID)

if right(PIDModule,7) = "tcc.exe" then
  with TakeCommand
    .tcommand("echo The .vbs is running from SCRIPT in tcc.exe")
  end With
else
  with WScript
    .StdOut.WriteLine "The .vbs is running from CSCRIPT.EXE"
  end With
end if

Set tk = Nothing

Posting this mainly for my future reference, but thought others might also find this useful.

Joe
 
Hmmm! I don't recall using SCRIPT so I thought I'd try it. Whenever I give it a .VBS file name, with or without an engine, TCC disappears. I get local crash dumps. Here's a bit of the analysis (by WinDbg) of one. Since it works for you ... got any ideas?

Code:
EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ffff7692240 (ntdll!RtlFailFast2)
   ExceptionCode: c0000409 (Security check failure or stack buffer overrun)
  ExceptionFlags: 00000001
NumberParameters: 1
   Parameter[0]: 000000000000000a
Subcode: 0xa FAST_FAIL_GUARD_ICALL_CHECK_FAILURE

PROCESS_NAME:  tcc.exe
 
I forgot about that (and didn't search). That was (obviously) not resolved. @Joe Caverly, what versions of Windows and TCC are you running? I have

Code:
TCC 28.02.18 x64
Microsoft Windows 10 Pro for Workstations
10.0.19044.1889 (2009, 21H2)

Here's a simple one that doesn't make TCC crash.

1662745830494.png
 
As I explained in the thread from November of 21, you cannot use WScript.Echo with the internal TCC Script command.

To do the same thing using the internal TCC Script command, run this code;
Code:
'echo.vbs
TakeCommand.tcommand("echo lastmod")
...as
Code:
script echo.vbs

Note that TakeCommand.tcommand will not work with either CScript.exe or WScript.exe

Joe
Code:
     _x64: 1
   _admin: 1
_elevated: 1

TCC  28.02.18 x64   Windows 10 [Version 10.0.19044.1889]
 
As I showed, a test .VBS with only Wscript.Echo didn't crash TCC. The other ones I tried, which did crash TCC, start like this.

Code:
Set iWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = iWMI.ExecQuery("SELECT ...
 
Hi @vefatica,
I explained this in post #5 of the thread from November of 21.

Rex has not updated the code for the internal Script command.

Microsoft has kept CSCRIPT.EXE and WSCRIPT.EXE updated and working in Windows 10.

GetObject will not work with the internal Script command.

I've tried on simple Windows Scriplet (.wsc) files, and all it does is crash and close TCC.

As you are a C++ programmer, you could write your own ActiveScript interface, (hopefully as a plugin), for use with TCC.

I had to go WayBack to find Microsoft Script Interfaces documentation, but you could use this as a starting point to create your own plugin Script command for TCC, if you are so inclined.

"Active scripting is regarded complete, and no longer under active development by Microsoft. However, the technology is still being supported by Microsoft's Sustaining Engineering Team, which is responsible for bug fixes and security enhancements. Furthermore, scripting engines will continue to be shipped with future releases of Microsoft Windows and IIS."

ADDED: COM in plain C goes into detail about ActiveScript.

Joe
 
Last edited:
Alas, COM (or any kind of object oriented programming) is not my forte.
 
I wanted to know if I was running a .vbs (VBScript) file from either the TCC Script command, or CScript.exe.

The following .vbs (VBScript) file can be run from either the TCC Script command, or CScript.exe, to determine where the .vbs is running from.
Code:
' VbsEdit Toolkit is part of VBSEdit.

Set tk = CreateObject( "VbsEdit.Toolkit" )

PID = tk.CurrentProcessID
PIDModule = tk.ModuleFilenameFromProcessId(PID)

if right(PIDModule,7) = "tcc.exe" then
  with TakeCommand
    .tcommand("echo The .vbs is running from SCRIPT in tcc.exe")
  end With
else
  with WScript
    .StdOut.WriteLine "The .vbs is running from CSCRIPT.EXE"
  end With
end if

Set tk = Nothing

Posting this mainly for my future reference, but thought others might also find this useful.

Joe
Here is a simpler method, not requiring the VbsEdit.Toolkit;
Code:
on error resume next
script  = "N"
ws = WScript.FullName
if err.number = 424 then 'Object Required
  script = "Y"
  err.clear
end if
On Error GoTo 0

StdOut ws

Sub StdOut (argv)
  If script = "Y" then
    TakeCommand.tcommand("echo " + argv)
  Else
    WScript.StdOut.WriteLine argv
  End if
End Sub

Posting mainly for my future reference.

Joe
 
Back
Top