From: Saran on
Hello. I'm trying to make a (vb)script that does sockets:

IE:

SET Test = WScript.CreateObject("MSWinsock.Winsock", "Test_")
SUB Test_Connect() : msgBox "Test::Connected" : END SUB

The problem is, the program in which the script runs within, doesn't let
me use the WScript object.

I get this error i nthe program that runs the script: Error '424';
Object required: 'WScript'

I runs fine is I run the script with wscript.exe or cscript.exe

I tried the following:

SET Test = CreateObject("MSWinsock.Winsock")
ConnectObject Test, "Test_"
SUB Test_Connect() : msgBox "Test::Connected" : END SUB

But I get this error: Type mismatch: 'ConnectObject'

I saw na example of ConnectObject byitself, which seems to be the same
as WScript.ConnectObject, so why wont it work? I just want to do sockets
and use events from it!

Thanks.


From: Saran on
Christoph Basedau wrote:
> 23.11.2005 19:54, Saran schrieb:
>
>> Hello. I'm trying to make a (vb)script that does sockets:
>>
>> IE:
>>
>> SET Test = WScript.CreateObject("MSWinsock.Winsock", "Test_")
>> SUB Test_Connect() : msgBox "Test::Connected" : END SUB
>>
>> The problem is, the program in which the script runs within, doesn't
>> let me use the WScript object.
>>
>> I get this error i nthe program that runs the script: Error '424';
>> Object required: 'WScript'
>>
>> I runs fine is I run the script with wscript.exe or cscript.exe
>>
>> I tried the following:
>>
>> SET Test = CreateObject("MSWinsock.Winsock")
>> ConnectObject Test, "Test_"
>> SUB Test_Connect() : msgBox "Test::Connected" : END SUB
>>
>> But I get this error: Type mismatch: 'ConnectObject'
>>
>> I saw na example of ConnectObject byitself, which seems to be the
>> same as WScript.ConnectObject, so why wont it work? I just want to
>> do sockets and use events from it!
>
> There is no 'ConnectObject' in VBScript itself, you have to use the
> method of WScript-Object. If you run your scripts outside WSH, you'll
> have no WScript-Object and no WScript.ConnectObject.

Than kyou for your reply. I've seen examples that show usage of both
CreateObject and ConnectObject without WScript.* so it should be
possible. I also recall seeing it in a refrence book about a year ago
(when I was in a book store looking at different programming books.) I
just can't figure out how exactly it went.

If not, is there a way ot manually instaniate WScript? Again, the
program I'm writing this script for runs the script "inside itself", and
everything that works normally from exploere/cmd.exe for vbscript works
in there, except the main WScript object. I need to create it manually.

I tried CreateObject("WScript") which did not work. Theres gotta be a
way.

> Other hosts expose different mechanisms for catching events, in IE
> and HTA for example you might use an <object>-tag and the <script
> for="WinSock" event="DataArrival"> syntax. Another possibility for
> VBS is using GetRef, which only works if the COM-Interface allows
> attaching function-pointers via PropertyGet.
> Maybe the "Scripting Events"-article of the MSDN-Clinick-column might
> help you:
> http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting04092001.asp


From: "Michael Harris (MVP)" <mikhar at mvps dot on
>>> I saw na example of ConnectObject byitself, which seems to be the
>>> same as WScript.ConnectObject, so why wont it work? I just want to
>>> do sockets and use events from it!
>>
>> There is no 'ConnectObject' in VBScript itself, you have to use the
>> method of WScript-Object. If you run your scripts outside WSH, you'll
>> have no WScript-Object and no WScript.ConnectObject.
>
> Than kyou for your reply. I've seen examples that show usage of both
> CreateObject and ConnectObject without WScript.* so it should be
> possible. I also recall seeing it in a refrence book about a year ago
> (when I was in a book store looking at different programming books.) I
> just can't figure out how exactly it went.


Christoph's statements are 100% correct. Your recollection of a non-WScript
version of ConnectObject may be wishful at best. If you want to consider a
third party component (still free in this case), the ScriptX component from
www.meadroid.com has comparable capabilities for event sinks/sources, but
the function names are not ConnectObject/DisconnectObject.


>
> If not, is there a way ot manually instaniate WScript? Again, the
> program I'm writing this script for runs the script "inside itself",
> and everything that works normally from exploere/cmd.exe for vbscript
> works in there, except the main WScript object. I need to create it
> manually.
> I tried CreateObject("WScript") which did not work. Theres gotta be a
> way.
>
>> Other hosts expose different mechanisms for catching events, in IE
>> and HTA for example you might use an <object>-tag and the <script
>> for="WinSock" event="DataArrival"> syntax. Another possibility for
>> VBS is using GetRef, which only works if the COM-Interface allows
>> attaching function-pointers via PropertyGet.
>> Maybe the "Scripting Events"-article of the MSDN-Clinick-column might
>> help you:
>> http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting04092001.asp

--
Michael Harris
Microsoft MVP Scripting




From: Saran on
Michael Harris (MVP) wrote:
>>>> I saw na example of ConnectObject byitself, which seems to be the
>>>> same as WScript.ConnectObject, so why wont it work? I just want to
>>>> do sockets and use events from it!
>>>
>>> There is no 'ConnectObject' in VBScript itself, you have to use the
>>> method of WScript-Object. If you run your scripts outside WSH,
>>> you'll have no WScript-Object and no WScript.ConnectObject.
>>
>> Than kyou for your reply. I've seen examples that show usage of both
>> CreateObject and ConnectObject without WScript.* so it should be
>> possible. I also recall seeing it in a refrence book about a year ago
>> (when I was in a book store looking at different programming books.)
>> I just can't figure out how exactly it went.
>
>
> Christoph's statements are 100% correct. Your recollection of a
> non-WScript version of ConnectObject may be wishful at best. If you
> want to consider a third party component (still free in this case),
> the ScriptX component from www.meadroid.com has comparable
> capabilities for event sinks/sources, but the function names are not
> ConnectObject/DisconnectObject.

I can take a look at it. Though, is there a way to manually instaniate
WScript? Again, the program I'm writing this script for runs the script
"inside itself", and everything that works normally from
exploere/cmd.exe for vbscript works in there, except the main WScript
object. I need to create it manually.

Thank you again.


>>> Other hosts expose different mechanisms for catching events, in IE
>>> and HTA for example you might use an <object>-tag and the <script
>>> for="WinSock" event="DataArrival"> syntax. Another possibility for
>>> VBS is using GetRef, which only works if the COM-Interface allows
>>> attaching function-pointers via PropertyGet.
>>> Maybe the "Scripting Events"-article of the MSDN-Clinick-column
>>> might help you:
>>> http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting04092001.asp
>
> --
> Michael Harris
> Microsoft MVP Scripting



--
Stan


From: "Michael Harris (MVP)" <mikhar at mvps dot on
> I can take a look at it. Though, is there a way to manually instaniate
> WScript? Again, the program I'm writing this script for runs the
> script "inside itself", and everything that works normally from
> exploere/cmd.exe for vbscript works in there, except the main WScript
> object. I need to create it manually.

The intrinsic WScript object is created/exposed only by the WSH hosts
(w/cscript.exe) and is not externally creatable by any other process. The
only externally creatable WSH provided objects are those with progids
(WScript.Shell and WScript.Network).

--
Michael Harris
Microsoft MVP Scripting