1

I am trying to perform an VBScript action while receiving email in the Masstransit application. The below code is the upload action. This code is working correctly while running outside on the Masstransit. But it is failing in masstransit in WScript createobject line itself.

This is my code

Option Explicit
' Setup session options
Dim sessionOptions, Protocol_Sftp
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
    .Protocol = Protocol_Sftp
    .HostName = "xxxxxx.com"
    .UserName = "xxxxxxxxxxxxx"
    .Password = "xxxxxxxxxxxxxx"
    .SshHostKeyFingerprint = "ssh-rsa 1024 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
' Connect
session.Open sessionOptions
' Upload files
Dim transferOptions, TransferMode_Binary
Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
transferOptions.TransferMode = TransferMode_Binary
Dim transferResult
Set transferResult = session.PutFiles("D:\testing-file.txt", "/", False, transferOptions)
' Throw on any error
transferResult.Check
' Print results
Dim transfer
For Each transfer In transferResult.Transfers
    WScript.Echo "Upload of " & transfer.FileName & " succeeded"
Next
' Disconnect, clean up
session.Dispose

I am receiving the below error:

Action script error: script error (vb_folderfiles.vbs, position 5.1): microsoft vbscript runtime error object required: “WScript” (0x800a01a8)

Ultimately, I tried with WScript and without WScript. Both are not working in the masstransit application. It is not creating the object.

But, this code is perfectly working outside of Masstransit. Please show some light on this.

Geert Bellekens
  • 11,687
  • 2
  • 20
  • 47
Rajesh
  • 382
  • 2
  • 7
  • 2
    Remove the `WScript.` what is the error?, it will not be the same. – user692942 May 09 '22 at 07:40
  • 2
    You get `Object required` because you are not running the script using the [Windows Scripting Host](https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/9bbdkx3k(v=vs.84)) (`wscript.exe` or `cscript.exe`), so you should just use `CreateObject` without the `WScript.` prefix. The other error will likely be `Can't create object` which relates to the `WinSCP.SessionOptions` prog id not being found the registry. See [activex can't create object by vbs but can by classic asp](https://stackoverflow.com/a/27713698). – user692942 May 09 '22 at 10:29
  • 2
    You may also find this [check list](https://stackoverflow.com/a/35985827/692942) useful for diagnosing the problem. – user692942 May 09 '22 at 10:32
  • It is a problem in masstransit. It is unable to create the winscp.sessionoption object. I need to do some configuration update in that application. Action script error: Script error (vb_folderfiles.vbs, position 10,1): Microsoft VBScript runtime error ActiveX component can’t create object: ‘WinSCP.SessionOptions’ (0x800A01AD) – Rajesh May 10 '22 at 11:33
  • 2
    This is pretty much what I was saying in the previous comments, would recommend looking at the checklist in the [previous comment](https://stackoverflow.com/questions/72168158/wscript-object-not-creating-in-masstransit?noredirect=1#comment127513962_72168158) and work through it. – user692942 May 10 '22 at 11:34
  • 1
    Thanks Buddy. As you suggested, the problem occurred in registry part. cscript was running in System32 as it has been registered in the registry But cscript was not running in SysWOW64 and it has not been registered in the registry, once we follow the same registration step of 32 bit in 64 bit then it started working %WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe WinSCPnet.dll /codebase /tlb:WinSCPnet32.tlb Actually both 32 bit and 64 bit both cscript has to be registrated to get the problem solved – Rajesh May 12 '22 at 07:08
  • 1
    Glad it help. If you did find it useful consider upvoting it. – user692942 May 12 '22 at 07:21

0 Answers0