[APORTE] [En Desarrollo] Interoperabilidad entre Windows Script Host y .NET

Iniciado por Aincrad, Febrero 17, 2023, 11:53:20 AM

Tema anterior - Siguiente tema

0 Miembros y 2 Visitantes están viendo este tema.

hola que tal, se acuerdan de este Post? : You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

En el que comente hace dos años, bueno ya me he puesto manos a la obra, y vengo a compartir lo que llevo hecho .



You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login Es una biblioteca COM que agrega la capacidad de usar .NET Framework de lenguajes scripts de windows más antiguos; como VBScript/JScript.

Caracteriticas :

  • Importación de .NET Framework o bibliotecas de terceros. hecho en .NET
  • Buscar clases y objetos
  • Creación y almacenamiento de Instancias [Desde script VBS/JS]
  • Gestión de objetos [Desde script VBS/JS]
  • Se admiten métodos estáticos. [Solucionado]

ahora bien, las caracteristicas que falta implementar :

  • Gestión de eventos ❌ [Esto es realmente necesario, pero no sé cómo hacerlo.]
  • Inventa una forma de hacer Callbacks desde .NET a VBS/JS Script. ❌
  • Cree un convertidor de tipos de .Net para poder ser usados desde el Script
  • Llamada de eventos [Esto es más simple, puedo obtener el puntero del evento y ejecutar ".Invoke" (VBS/JS) o RaiseEvent desde .NET]

las caracteristicas que tienen ❌ , significa que no tengo ni idea de como hacerlo.
Cualquier caracteristica adicional, son libres de comentar.



Como usar?:

1) Descargue la libreria COM y registrela. (el .zip ya trae un .bat , para registrar la libreria, ejecute el "Register COM.bat")

Descarga : You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

2) Cree su Script, agregare dos ejemplos en VBS .

- Cree y Maneje un Formulario .NET (Winform)

Código: vb
' Call Core
Dim InteropDotNet  : Set InteropDotNet = CreateObject("Script.Interop.Net.Linker")
' Create Import/using (equivalent)
Dim AssemblyTarget : Set AssemblyTarget = InteropDotNet.GetAssembly("System.Windows.Forms")
' Get Form Class From AssemblyTarget 
Dim ClassType : Set ClassType = AssemblyTarget.GetTypeByAssembly("Form")
' Create New Form Instance.
Dim FormNewInstance : Set FormNewInstance = ClassType.CreateInstance()
' Set Form Title
FormNewInstance.Text = "New Form"
' Show Form
FormNewInstance.ShowDialog()

 - Leer un archivo de texto (Desde .NET)

Código: vb
'File Path Example
Dim FilePath : FilePath = "File.txt"

' Call Core
Dim InteropDotNet  : Set InteropDotNet = CreateObject("Script.Interop.Net.Linker")
' Create Import/using (equivalent)
Dim AssemblyTarget : Set AssemblyTarget = InteropDotNet.GetAssembly("mscorlib")
' Get Form Class From AssemblyTarget 
Dim ClassType : Set ClassType = AssemblyTarget.GetTypeByAssembly("File")

'Get Methods By Name and Result Type
Dim Methods : Set Methods = ClassType.GetMethods("ReadAllText!String")

'Filter By Parameters and Call Function -> System.IO.File.ReadAllText(String)
Dim Result : Result = Methods.InvokeCall("-String " & FilePath)

' Show Content
Msgbox Result



Contribuciones

Son libres de ayudar en este proyecto, pueden comentar ideas o aportar directamente al codigo.

Source Code : You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Gracias por leer!