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.
Printable View
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.
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
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.
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
What is sub7 ???
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 :p.
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.
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.
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
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!
when you use FindWindow You can either use the window class OR the caption.
Spy++ tells you the window class for you, as that is most likely to stay constant over the use of the program.
So all i have to do is find the class name of the program i am interested in and thats it...yeah!
Thanks
Spy++ really confuses me :confused:
I recomend PatorJKs API Spy
http://www.patorjk.com/downloads/apispy50.zip
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 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.
That's clever. I'll look into that.
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
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.
coool
I modified mine a little so it would show the hwnd too...
:)
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!
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
Thanks Megatron. Anyone else got any suggestions. I think we'll have a full-fledged Spy program of our own soon!
what is GetParent used for?
and would i use it(GetParent) to get the parents caption and class?
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.
The reason I used GetParent was for the self immunity feature. It will ignore any window that is a child of our app.
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...
:)