My module's not working in some computers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bnashenas1984
    Contributor
    • Sep 2007
    • 257

    #1

    My module's not working in some computers

    Hi everyone
    I'v been programming a simple task and process manager which is working fine now but the problem is that my program does NOT work on some computers.
    I think it must have something to do with DLL files.
    Actually I'm not so good at VB. I just copied some modules from internet and using them like the instruction.
    I post my program below maybe someone can help me fix it.

    Here is what I do to get the address of start menu to add icon and run the program at startup:
    Code:
    Dim mShell
    Set mShell = CreateObject("WScript.Shell")
    txtpath = mShell.SpecialFolders("Startup")
    And below is the module I use to close windows by using their title showing in task bar :

    Code:
    Private Declare Function PostMessage Lib "user32" _
                                         Alias "PostMessageA" _
                                         (ByVal hwnd As Long, _
                                          ByVal wMsg As Long, _
                                          ByVal wParam As Long, _
                                          lParam As Any) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetWindow Lib "user32" _
                                       (ByVal hwnd As Long, _
                                        ByVal wCmd As Long) As Long
    Private Declare Function GetWindowText Lib "user32" _
                                           Alias "GetWindowTextA" _
                                           (ByVal hwnd As Long, _
                                            ByVal lpString As String, _
                                            ByVal cch As Long) As Long
    Private Declare Function GetClassName Lib "user32" _
                                          Alias "GetClassNameA" _
                                          (ByVal hwnd As Long, _
                                           ByVal lpClassName As String, _
                                           ByVal nMaxCount As Long) _
                                           As Long
    Private Const GW_HWNDFIRST = 0
    Private Const GW_HWNDLAST = 1
    Private Const GW_HWNDNEXT = 2
    Private Const GW_HWNDPREV = 3
    Private Const GW_OWNER = 4
    Private Const GW_CHILD = 5
    Private Const WM_CLOSE = &H10
    
    Function FindWindowHwndLike(hWndStart As Long, _
                                ClassName As String, _
                                WindowTitle As String, _
                                level As Long, _
                                lHolder As Long) As Long
    
        'finds the first window where the class name start with ClassName
        'and where the Window title starts with WindowTitle, returns Hwnd
        '----------------------------------------------------------------
        Dim hwnd As Long
        Dim sWindowTitle As String
        Dim sClassName As String
        Dim r As Long
    
        'Initialize if necessary. This is only executed
        'when level = 0 and hWndStart = 0, normally
        'only on the first call to the routine.
        If level = 0 Then
            If hWndStart = 0 Then
                hWndStart = GetDesktopWindow()
            End If
        End If
    
        'Increase recursion counter
        level = level + 1
    
        'Get first child window
        hwnd = GetWindow(hWndStart, GW_CHILD)
    
        Do Until hwnd = 0
    
            'Search children by recursion
            lHolder = FindWindowHwndLike(hwnd, _
                                         ClassName, _
                                         WindowTitle, _
                                         level, _
                                         lHolder)
    
            'Get the window text
            sWindowTitle = Space$(255)
            r = GetWindowText(hwnd, sWindowTitle, 255)
            sWindowTitle = Left$(sWindowTitle, r)
    
            'get the class name
            sClassName = Space$(255)
            r = GetClassName(hwnd, sClassName, 255)
            sClassName = Left$(sClassName, r)
    
            If InStr(1, sWindowTitle, WindowTitle, vbBinaryCompare) > 0 And _
               sClassName Like ClassName & "*" Then
                FindWindowHwndLike = hwnd
                lHolder = hwnd
                Exit Function
            End If
    
            'Get next child window
            hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    
        Loop
    
        FindWindowHwndLike = lHolder
    
    End Function
    
    Function CloseApp(ByVal strApp As String, _
                      ByVal strClass As String) As Long
    
        'will find a window based on:
        'the partial start of the Window title and/or
        'the partial start of the Window class
        'and then close that window
        'for example, this will close Excel:
        'CloseApp "", "XLM" and this will:
        'CloseApp "Microsoft Excel", ""
        'but this won't: CloseApp "", "LM"
        'it will only close the first window that
        'fulfills the criteria
        'will return Hwnd if successfull, and 0 if not
        '---------------------------------------------
    
        Dim hwnd As Long
    
        On Error GoTo ERROROUT
    
        hwnd = FindWindowHwndLike(0, _
                                  strClass, _
                                  strApp, _
                                  0, _
                                  0)
    
        If hwnd = 0 Then
            CloseApp = 0
            Exit Function
        End If
    
        'Post a message to the window to close itself
        '--------------------------------------------
        PostMessage hwnd, WM_CLOSE, 0&, 0&
    
        CloseApp = hwnd
    
        Exit Function
    ERROROUT:
        On Error GoTo 0
        CloseApp = 0
    End Function
    I'll really appreciate if someone tell me why this is just working on some computers and not all of them. Is there a way to fix it?

    Thanks / B...
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    All those are API functions.

    What exactly is the error message ?

    Comment

    • bnashenas1984
      Contributor
      • Sep 2007
      • 257

      #3
      Hi again and thanks for the reply
      Actualy I don't get any error messages but when I tried to run the program on different computers it worked on 5 of then but not the other 2.

      I thought there might be something wrong with DLL files or something like that.
      I don't know if these API's use any DLL file or not that's why i'm posting this question here

      thanks again

      Comment

      • !NoItAll
        Contributor
        • May 2006
        • 297

        #4
        If I had to guess (and I do) I'd bet the DLLs are fine, but the VBScripting engine (which you call for when you create the WScript object) is not installed, or even disabled on those two machines.
        Download and install the VB Scripting Runtime engine on those two machines.

        Des

        Comment

        Working...