1 Year
Discussion Span
Last Post by cambalinho

i created the cls file:

Imports System
    Imports System.Runtime.InteropServices
    Imports Microsoft.Win32

    Namespace WindowScriptingObject

        <Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
        InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
       Public Interface _WindowScriptingObject
            <DispId(1)> Function ActiveWindow() As Integer
            <DispId(2)> Function WindowText(ByVal hWnd As Integer) As String
        End Interface

        <Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
         ClassInterface(ClassInterfaceType.None), _
         ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
            Implements _WindowScriptingObject

            Public WindowScriptingObject()

            Public Declare Auto Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow"() As Integer
            Public Declare Auto Function GetWindowText Lib "user32.dll" (ByVal hwnd As Int32, <Out()> ByVal lpString As System.Text.StringBuilder, ByVal cch As Int32) As Int32
            Public Function ActiveWindow() As Integer Implements _WindowScriptingObject.ActiveWindow

            End Function

            Public Function WindowText(hwnd as Integer) As String Implements _WindowScriptingObject.WindowText
     on error resume next
     Dim b As New System.Text.StringBuilder(ChrW(0), 512)
                    Dim ret = GetWindowText(hWnd, b, b.Capacity)
     WindowText = b.tostring
            End Function

        End Class

    End Namespace

and the bat file:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:library /out:"%userprofile%\desktop\win32.dll" "%userprofile%\desktop\win32.cls" /verbose

    "C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase "%userprofile%\desktop\win32.dll" /tlb:"%userprofile%\desktop\win32.tlb" /v

    If /i "%cmdcmdline:~0,6%"=="cmd /c" pause

after click on bat file the dll and tlb file was created.
heres the sample:

Set wso=CreateObject("WindowScriptingObject")
    x = wso.ActiveWindow
    msgbox x, , "vbs"
    msgbox wso.windowtext(x), , "vbs"

error message:
'the ActiveX component can't create a 'WindowScriptingObject' object'

so what i'm doing wrong?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.