creating a type library from a windows script component
-
jeudi 26 avril 2012 13:32Hi
Im trying to use a windows script component to create a com object and I need to create a tlb file. If I register the wsc file it is successful and can be used from another script but i want to use it from other languages.
If I try right click "generate type library I get some usage guidance but no tlb file
Trying to generate it using script gives me an error when trying the write method of the scriplet.typelib object saying object doesnt support this action
and when trying t ouse a command line it comes back with "Missing Entry:TypeLib"
Does anyone have any thoughts about where im going wrong?
Toutes les réponses
-
jeudi 26 avril 2012 13:39
Unfortunately yu question is not really a scripting question but is a developers question.
(I know - I am playing chicken and egg but its true)
You might be able to create one by hand but ther eis no eally automatic mthod for a script compoent as it is just a script wrapped by a component. The properies and methods are generated at run time. There is no DLL and not library code.
A script component willbe visible from all other languages that can use CoCreateObject. The interfaces will not be discoverable but, I believe they can be access via 'Invoke'.
¯\_(ツ)_/¯
-
jeudi 26 avril 2012 14:08With the greatest of respect, msdn says that you can do this and even that it improves performance.. I know I am dumb but what is this article all about http://msdn.microsoft.com/en-us/library/sh9ete15(v=vs.85).aspx
regards
Rob -
jeudi 26 avril 2012 15:44Modérateur
Hi,
It is possible to generate a type library for a script component. Why do you need to do it?
Bill
-
jeudi 26 avril 2012 16:33Modérateur
Hi,
Sorry, I missed the part where you said you wanted to use the script component from other languages. You can register the script component using the command line as follows:
%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\scrobj.dll,GenerateTypeLib -name:"TypelibName" -file:"path\file.tlb" -doc:\"Typelib doc string\" -guid:"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" -major:n -minor:n "path\file.wsc"The above command should be all on one line. Note that the documentation is a little lacking; the scrobj.dll function is really called GenerateTypeLib, not TypeLib as listed in the documentation. The -doc option requires the backslashes if the doc string contains spaces. Use numbers for the major and minor version numbers (e.g., -major:1 -minor:0). The -guid option needs a custom GUID.
Bill
- Modifié Bill_StewartMicrosoft Community Contributor, Moderator jeudi 26 avril 2012 16:37 Corrections
- Proposé comme réponse Richard MuellerMVP, Moderator dimanche 29 avril 2012 02:29
-
jeudi 26 avril 2012 16:36
With the greatest of respect, msdn says that you can do this and even that it improves performance.. I know I am dumb but what is this article all about http://msdn.microsoft.com/en-us/library/sh9ete15(v=vs.85).aspx
regards
RobYes I remember that article. That is what I call manually geneating a type library from a custom file.
Note the requirements for the component:
These things have to be put into the compoennt by you in order to generate a TLB. You also have to supply a GUID thatis unique using guidgen or other method of getting a guid.
Have you doe all of that?
Your WSC has to be designed correctly or it will choke. I can generate a tlb from a WSC built with PrimalScript. I can also build a much simpler WSC that cannot be used to generate a typelib.
I suspect your WSC is not correctly built. I have had problems in teh past with generating a tlb with hand made components especially ones built according to the MS samples frmo early WSC.
¯\_(ツ)_/¯
-
jeudi 26 avril 2012 17:27
Here is a sample component I just vuit and generated a tlb for. It contains all of teh required sections.
<?xml version="1.0" ?> <package> <comment> Primalscript wizard generated file. </comment> <component id="TestComponent"> <?component error="true" debug="true" ?> <registration progid="TestComponent.WSC" classid="{664E22FF-644D-4BAF-9C5D-7E319E44ECE8}" description="TestComponent" version="1.0"> <script language="VBScript"> <![CDATA[ Function Register() Dim TypeLib Set TypeLib = CreateObject("Scriptlet.TypeLib") TypeLib.AddURL "TestComponent.WSC" TypeLib.Path = "TestComponentWSC.tlb" TypeLib.Doc = "TestComponent" TypeLib.Name = "TestComponentWSC.tlb" TypeLib.MajorVersion = 1 TypeLib.MinorVersion = 0 TypeLib.Write End Function Function Unregister() End Function ]]> </script> </registration> <public> <property name="Message"> <get/> <put/> </property> <method internalname="NewMsgInt" name="NewMsg"> <parameter name="newMessage"/> </method> </public> <script id="TestComponent" language="VBScript"> <![CDATA[ ' ' Primalscript 2007 Windows Script Wizard generated ' dim Message Message = "Default Message" function get_Message() get_Message = Message end function function put_Message(newValue) Message = newValue end function function NewMsgInt(newMessage) NewMsgInt = Message Message=newMessage end function ]]> </script> </component> </package>
Note the required CDATA section around the code to protect it from breakage in XML.
Here is the test script that I have run.
Set test = CreateObject("TestComponent.WSC")
test.Message="updated message"
MsgBox test.NewMsg("xxx")
MsgBox test.NewMsg("zzz")The components will not work under PowerShell with methods. Properties work fine but method signaturew seem to be incorrect for PowerShell.
Even if you create a type library you cannot use the component as an 'early bound' component. script components are only late bound even with a tlb.
¯\_(ツ)_/¯
- Proposé comme réponse Richard MuellerMVP, Moderator dimanche 29 avril 2012 02:29
-
jeudi 26 avril 2012 19:22
Hi,
Sorry, I missed the part where you said you wanted to use the script component from other languages. You can register the script component using the command line as follows:
%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\scrobj.dll,GenerateTypeLib -name:"TypelibName" -file:"path\file.tlb" -doc:\"Typelib doc string\" -guid:"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" -major:n -minor:n "path\file.wsc"The above command should be all on one line. Note that the documentation is a little lacking; the scrobj.dll function is really called GenerateTypeLib, not TypeLib as listed in the documentation. The -doc option requires the backslashes if the doc string contains spaces. Use numbers for the major and minor version numbers (e.g., -major:1 -minor:0). The -guid option needs a custom GUID.
Bill
Bill - that really desn't work because we need to use the GUID inside of the component and the spec in the component. Once that is inserted you can just register thr component and it will generate the tlb.
The following goes into the component:
Function Register()
Dim TypeLib
Set TypeLib = CreateObject("Scriptlet.TypeLib")
TypeLib.AddURL "TestComponent.WSC"
TypeLib.Path = "TestComponentWSC.tlb"
TypeLib.Doc = "TestComponent"
TypeLib.Name = "TestComponentWSC.tlb"
TypeLib.MajorVersion = 1
TypeLib.MinorVersion = 0
TypeLib.Write
End FunctionNow the rundll callyou have specified is called automatically when the component is regsitered and teh TLB is created in teh same folder as teh component using those answers. You methof is sueful fo r old components that were not buit with this spec avaialble. I beleive it is a big pain in the neck to rebuild them just to use this so we can use the commandline call to GenerateTypeLib.
This is the perferred method as long as you are using the XML foll package declaration.
¯\_(ツ)_/¯
-
jeudi 26 avril 2012 21:02Modérateur
Bill - that really desn't work because we need to use the GUID inside of the component and the spec in the component.
Hi,
Actually it does work (I tested this earlier today). Also, the documentation states thus:
(Property) A GUID for the type library. (This is not the GUID for the script component.) If you do not provide one, the TypeLib object will create one, but then the type library will have a different GUID on each machine.
For troubleshooting and deployment purposes, I would recommend specifying a specific typelib GUID (not the same GUID as the component). Otherwise the GUID will be dynamically generated every time the component gets installed.
Bill
-
vendredi 27 avril 2012 00:54
Bill- good point. I willtest it.
I actually thing we can supply the public and permanent GUID inside to theregister function of the component.
Much of the documentation for this is old from early WSC days. WSC was subtly upgraded but ther is littel documentation. Most of what I had learned was from inspectin g some MS components on some no-longer-exisiting web pages.
WSC used to work fromn POwerSHell, I cannot understand why a newly created component won't work yet it works in VBScript and in VBA but in VBA we cannot reference the TLB.
¯\_(ツ)_/¯
-
lundi 30 avril 2012 08:00
Hi,
Just to let you know the reason why my typelibrary wasnt being created. I used the windows scripting host wizard to create the wsc file and I didnt untick "special implements support".
This added an <implements/> tag into the component and this was preventing the right click build typelibrary from working.
thanks for your help guys.. one to remember for the future..
Robert- Marqué comme réponse Richard MuellerMVP, Moderator samedi 5 mai 2012 15:09
-
samedi 5 mai 2012 15:09Modérateur
As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.
Richard Mueller - MVP Directory Services

