Results 1 to 26 of 26

Thread: What code?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Cool

    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.

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    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.

  4. #4
    Guest
    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

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    sub7

    What is sub7 ???
    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.

  6. #6
    Guest
    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Wink 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.

  8. #8
    Guest
    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

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Talking 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!

  10. #10
    Guest
    when you use FindWindow You can either use the window class OR the caption.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Thumbs up Kool..

    So all i have to do is find the class name of the program i am interested in and thats it...yeah!
    Thanks

  13. #13
    Guest
    Spy++ really confuses me
    I recomend PatorJKs API Spy

    http://www.patorjk.com/downloads/apispy50.zip

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  15. #15
    Guest
    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.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  18. #18
    Guest
    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.

  19. #19
    Guest
    coool
    I modified mine a little so it would show the hwnd too...

  20. #20
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  21. #21
    Guest
    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

  22. #22
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  23. #23
    Guest
    what is GetParent used for?
    and would i use it(GetParent) to get the parents caption and class?

  24. #24
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  25. #25
    Guest
    The reason I used GetParent was for the self immunity feature. It will ignore any window that is a child of our app.

  26. #26
    Guest
    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
  •  



Click Here to Expand Forum to Full Width