|
-
Aug 13th, 2000, 11:46 PM
#1
Thread Starter
Addicted Member
I can write a code that tells of a certain .exe's filesize
but i would like to know what code or what would i have to do to make a code that compares if the program is currently running or not??
Thank you.
-
Aug 14th, 2000, 12:10 AM
#2
You use the FindWindow function to find it by knowing it's caption.
Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Dim h
h = FindWindow(vbNullString, "Calculator")
If h = 0 Then
MsgBox "Window was not found!", 16
Else
MsgBox "Found!": Exit Sub
End If
-
Aug 14th, 2000, 12:53 AM
#3
Thread Starter
Addicted Member
Thank you matthew
Ok next question...using the same code above..how could i make program watch too see if the program that it is watching for (calculator) for example too open..and then if calculator opens have it close.
I think there is a api for closing the window called "closewindow" but am really really need to know the code to watch for calculator to open
Thanks.
Oh by the way..just too let ya know i made a program that deletes the sub7 server from your comp. but am sure you can make your own.
Thanks again.
-
Aug 14th, 2000, 01:08 AM
#4
Simple. Just keep the code in a timer and its interval set at 100. Than use this code:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Sub Timer1_Timer()
Dim h
h = FindWindow(vbNullString, "Calculator")
If h = 0 Then
Exit Sub
Else
MsgBox "FOUND: CLOSING WINDOW!", 16
If h <> 0 Then
SendMessage h, WM_CLOSE, 0, 0
SendMessage h, WM_DESTROY, 0, 0
End If
End If
End Sub
-
Aug 14th, 2000, 02:12 AM
#5
Lively Member
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Aug 14th, 2000, 05:13 AM
#6
Sophtware, can you send me it? I probably could make my own, but I haven't a clue as to where to start. Please send, and I hope you aren't trying to trojan me either .
Email: [email protected]
Thanks, I'd appreciate it, if you are telling the truth .
And AKA, Sub 7 is a Trojan that I got and someone has access to all your files and everything you do..mostly everything.
Here is a topic I started on SubSeven Trojan.
-
Aug 14th, 2000, 08:43 AM
#7
Thread Starter
Addicted Member
Yeah ill send it to ya
Matthew all you have to do is go to http://www.zonelabs.com and download the zonealaram firewall and you wont have to worry about the sub7 issue...i got that firewall and i havent had no problems with sub7.
Dont worry i aint no ass that gets peoples trust and then screws em over.
-
Aug 14th, 2000, 08:45 AM
#8
When closing windows, it's a good idea to use the DestroyWindow function. Although, you can also do the SendMessage equivilent by sending WM_NCDESTROY and WM_DESTROY.
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10
Private Sub Timer1_Timer()
Dim hApp As Long
hApp = FindWindow(vbNullString, "Calculator")
If hApp <> 0 Then
SendMessage hApp, WM_CLOSE, 0, 0
DestroyWindow hApp
End If
End Sub
-
Aug 14th, 2000, 02:54 PM
#9
Thread Starter
Addicted Member
Thanks all
Thanks for all the helpful tips..i will use them in future projects..but i have a question still,
Is there a function that can find a program that is currently open and running? i cant use Findwindow api cause i dont know the title of the window of the program..
I have the pathname already set in my program but ill i need know is to know of a api that can find the program only when it starts to run that way i can deal with it when it runs. i hope am making sense? lol!
-
Aug 14th, 2000, 03:10 PM
#10
when you use FindWindow You can either use the window class OR the caption.
-
Aug 14th, 2000, 03:15 PM
#11
Monday Morning Lunatic
Spy++ tells you the window class for you, as that is most likely to stay constant over the use of the program.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 03:21 PM
#12
Thread Starter
Addicted Member
Kool..
So all i have to do is find the class name of the program i am interested in and thats it...yeah!
Thanks
-
Aug 14th, 2000, 03:45 PM
#13
Spy++ really confuses me
I recomend PatorJKs API Spy
http://www.patorjk.com/downloads/apispy50.zip
-
Aug 14th, 2000, 03:48 PM
#14
Monday Morning Lunatic
I suppose I'm biased because of my C++ background (I knew C++ before I knew VB), so I feel more at home with complicated tools. What I would like to know is how you highlight the windows like Spy++ and PSP do.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 04:18 PM
#15
I have not yet tried this, but logically speaking, you can use WindowFromPoint to get the hWnd of the window that the mouse is over and use GetWindowRect to get the rectangle. From there, you can draw an outline using the Rectangle function.
-
Aug 14th, 2000, 04:21 PM
#16
Monday Morning Lunatic
That's clever. I'll look into that.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 04:30 PM
#17
Monday Morning Lunatic
Check this out. Put two TextBoxes and a Timer (with interval 10) onto a form. Add the following code to the form, then run.
Code:
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint 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 Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim ghWnd As Long
Private Sub Timer1_Timer()
Dim mypt As POINTAPI
GetCursorPos mypt
ghWnd = WindowFromPoint(mypt.x, mypt.y)
Dim mystr As String * 400
GetWindowText ghWnd, mystr, 400
Text1.Text = mystr
GetClassName ghWnd, mystr, 400
Text2.Text = mystr
End Sub
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 04:34 PM
#18
cool!
I just used the Spy++ Findwindow tool,
that is awesome.
I was always just trying to figure stuff out from the big list that you see when you start it.
-
Aug 14th, 2000, 04:37 PM
#19
coool
I modified mine a little so it would show the hwnd too...
-
Aug 14th, 2000, 04:44 PM
#20
Monday Morning Lunatic
There we go. Shows that it doesn't have to be massive to be useful. A few tweaks and it'll be a proper program in no time!
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 05:09 PM
#21
Parksie: Try the following. I have added a couple more features. (Always On Top and self-immunity).
Code:
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint 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 Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim Wnd As Long
Dim sName As String
Dim sClass As String
Private Sub Form_Activate()
SetWindowPos Me.hwnd, -1, 0, 0, Me.Width / 15, Me.Height / 15, 0
End Sub
Private Sub Timer1_Timer()
Dim lPoint As POINTAPI
Dim sName As String * 400
Dim sClass As String * 400
GetCursorPos lPoint
ghWnd = WindowFromPoint(lPoint.x, lPoint.y)
If GetParent(ghWnd) = Me.hwnd Or ghWnd = Me.hwnd Then
Text1 = ""
Text2 = ""
Exit Sub
End If
GetWindowText ghWnd, sName, 400: Text1.Text = sName
GetClassName ghWnd, sClass, 400: Text2.Text = sClass
End Sub
-
Aug 14th, 2000, 05:14 PM
#22
Monday Morning Lunatic
Thanks Megatron. Anyone else got any suggestions. I think we'll have a full-fledged Spy program of our own soon!
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 05:17 PM
#23
what is GetParent used for?
and would i use it(GetParent) to get the parents caption and class?
-
Aug 14th, 2000, 05:20 PM
#24
Monday Morning Lunatic
GetParent allows you to get the parent window's handle. For example, if you gave a text box's handle, it would return the handle of the window with the text box. From there you can get the caption and class name. I've also nearly finished a slightly tidier VBSpy application.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2000, 05:38 PM
#25
The reason I used GetParent was for the self immunity feature. It will ignore any window that is a child of our app.
-
Aug 14th, 2000, 05:44 PM
#26
wow, these are incredibly easy API Calls..
I just made a fully functional API SPy that shows the hwnd caption and class of the parent.
I also have a hot key so you can pause it.... and unpause it...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|