473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

My module's not working in some computers

258 100+
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:
Expand|Select|Wrap|Line Numbers
  1. Dim mShell
  2. Set mShell = CreateObject("WScript.Shell")
  3. txtpath = mShell.SpecialFolders("Startup")
  4.  
And below is the module I use to close windows by using their title showing in task bar :

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function PostMessage Lib "user32" _
  2.                                      Alias "PostMessageA" _
  3.                                      (ByVal hwnd As Long, _
  4.                                       ByVal wMsg As Long, _
  5.                                       ByVal wParam As Long, _
  6.                                       lParam As Any) As Long
  7. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  8. Private Declare Function GetWindow Lib "user32" _
  9.                                    (ByVal hwnd As Long, _
  10.                                     ByVal wCmd As Long) As Long
  11. Private Declare Function GetWindowText Lib "user32" _
  12.                                        Alias "GetWindowTextA" _
  13.                                        (ByVal hwnd As Long, _
  14.                                         ByVal lpString As String, _
  15.                                         ByVal cch As Long) As Long
  16. Private Declare Function GetClassName Lib "user32" _
  17.                                       Alias "GetClassNameA" _
  18.                                       (ByVal hwnd As Long, _
  19.                                        ByVal lpClassName As String, _
  20.                                        ByVal nMaxCount As Long) _
  21.                                        As Long
  22. Private Const GW_HWNDFIRST = 0
  23. Private Const GW_HWNDLAST = 1
  24. Private Const GW_HWNDNEXT = 2
  25. Private Const GW_HWNDPREV = 3
  26. Private Const GW_OWNER = 4
  27. Private Const GW_CHILD = 5
  28. Private Const WM_CLOSE = &H10
  29.  
  30. Function FindWindowHwndLike(hWndStart As Long, _
  31.                             ClassName As String, _
  32.                             WindowTitle As String, _
  33.                             level As Long, _
  34.                             lHolder As Long) As Long
  35.  
  36.     'finds the first window where the class name start with ClassName
  37.     'and where the Window title starts with WindowTitle, returns Hwnd
  38.     '----------------------------------------------------------------
  39.     Dim hwnd As Long
  40.     Dim sWindowTitle As String
  41.     Dim sClassName As String
  42.     Dim r As Long
  43.  
  44.     'Initialize if necessary. This is only executed
  45.     'when level = 0 and hWndStart = 0, normally
  46.     'only on the first call to the routine.
  47.     If level = 0 Then
  48.         If hWndStart = 0 Then
  49.             hWndStart = GetDesktopWindow()
  50.         End If
  51.     End If
  52.  
  53.     'Increase recursion counter
  54.     level = level + 1
  55.  
  56.     'Get first child window
  57.     hwnd = GetWindow(hWndStart, GW_CHILD)
  58.  
  59.     Do Until hwnd = 0
  60.  
  61.         'Search children by recursion
  62.         lHolder = FindWindowHwndLike(hwnd, _
  63.                                      ClassName, _
  64.                                      WindowTitle, _
  65.                                      level, _
  66.                                      lHolder)
  67.  
  68.         'Get the window text
  69.         sWindowTitle = Space$(255)
  70.         r = GetWindowText(hwnd, sWindowTitle, 255)
  71.         sWindowTitle = Left$(sWindowTitle, r)
  72.  
  73.         'get the class name
  74.         sClassName = Space$(255)
  75.         r = GetClassName(hwnd, sClassName, 255)
  76.         sClassName = Left$(sClassName, r)
  77.  
  78.         If InStr(1, sWindowTitle, WindowTitle, vbBinaryCompare) > 0 And _
  79.            sClassName Like ClassName & "*" Then
  80.             FindWindowHwndLike = hwnd
  81.             lHolder = hwnd
  82.             Exit Function
  83.         End If
  84.  
  85.         'Get next child window
  86.         hwnd = GetWindow(hwnd, GW_HWNDNEXT)
  87.  
  88.     Loop
  89.  
  90.     FindWindowHwndLike = lHolder
  91.  
  92. End Function
  93.  
  94. Function CloseApp(ByVal strApp As String, _
  95.                   ByVal strClass As String) As Long
  96.  
  97.     'will find a window based on:
  98.     'the partial start of the Window title and/or
  99.     'the partial start of the Window class
  100.     'and then close that window
  101.     'for example, this will close Excel:
  102.     'CloseApp "", "XLM" and this will:
  103.     'CloseApp "Microsoft Excel", ""
  104.     'but this won't: CloseApp "", "LM"
  105.     'it will only close the first window that
  106.     'fulfills the criteria
  107.     'will return Hwnd if successfull, and 0 if not
  108.     '---------------------------------------------
  109.  
  110.     Dim hwnd As Long
  111.  
  112.     On Error GoTo ERROROUT
  113.  
  114.     hwnd = FindWindowHwndLike(0, _
  115.                               strClass, _
  116.                               strApp, _
  117.                               0, _
  118.                               0)
  119.  
  120.     If hwnd = 0 Then
  121.         CloseApp = 0
  122.         Exit Function
  123.     End If
  124.  
  125.     'Post a message to the window to close itself
  126.     '--------------------------------------------
  127.     PostMessage hwnd, WM_CLOSE, 0&, 0&
  128.  
  129.     CloseApp = hwnd
  130.  
  131.     Exit Function
  132. ERROROUT:
  133.     On Error GoTo 0
  134.     CloseApp = 0
  135. End Function
  136.  
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...
Oct 26 '08 #1
3 1668
debasisdas
8,127 Expert 4TB
All those are API functions.

What exactly is the error message ?
Oct 26 '08 #2
bnashenas1984
258 100+
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
Oct 26 '08 #3
!NoItAll
297 100+
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
Oct 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brad Tilley | last post by:
When memory usage is a concern, is it better to do: from X import Y or import X Also, is there a way to load and unload modules as they are needed. I have some scripts that sleep for...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
2
by: | last post by:
Hi, This does sound like a bit of a weird thing to ask so I will state my question and then further down explain why I am trying to do it. So if you have the answer then reply! Or if you...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
8
by: Bellum | last post by:
I got my teacher to intall python on one of the computers, but python doesn't seem to want to compile modules. I used the same code I use at home, but I get ImportError: No module named password ...
3
by: Erik Johnson | last post by:
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that...
32
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many...
9
by: Larry Hale | last post by:
I've heard tell of a Python binding for libmagic (file(1) *nixy command; see http://darwinsys.com/file/). Generally, has anybody built this and worked with it under Windows? The only thing I've...
0
by: Fredrik Lundh | last post by:
Jeff Dyke wrote: so how did that processing use the "mymodulename" name? the calling method has nothing to do with what's considered to be a local variable in the method being called, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.