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: -
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 : -
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...
3 1668
All those are API functions.
What exactly is the error message ?
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |