Results 1 to 12 of 12

Thread: How can close any file by title description

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    How can close any file by title description

    Hello everyone,

    How can close any file by title description.

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How can close any file by title description

    Not sure what you are asking. You can close any file that you have opened. Usually you do this based on the file number used to open it.

    If you are asking how to close a file opened by another program then that is a completely different type of thing and one that you shouldn't even try to do.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    Re: How can close any file by title description

    Hi DataMiser,

    i need close the exe file.

    Example: I want when run my program - if find Notepad open program I want to close it according to the title of the window.

  4. #4
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: How can close any file by title description

    Why do you feel the need to do this?

    You do realise that Window Titles can change as applications run, don't you?
    Just try opening different files in Notepad.

    "Randomly" killing off processes is only going to get you Bug Reports from your Users who were using whichever application process you killed before they'd saved their data in it.

    Take a step back and tell us; what [Big Picture] problem are you trying to solve here?

    Regards, Phill W.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    Re: How can close any file by title description

    For Example

    Name:  150884053375531.jpg
Views: 114
Size:  9.6 KB

  6. #6
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: How can close any file by title description

    Very pretty - but to what end?

    Why do you want to kill external processes, by Window Title or any other means?
    This is not "normal" behavior for a VB program.

    Is there a particular program that you want to get rid of?

    To what practical use do you intend to put this, even assuming you (we?) can get it to work?

    Or is this just an academic exercise, to find out what you can (and, in many cases, can't) do?

    Regards, Phill W.

  7. #7
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,034

    Re: How can close any file by title description

    Hi Phill,

    I think coldlove means this..
    Code:
    Private Sub Command1_Click()
     TerminateProcess ("notepad.exe")
    End Sub
    Private Sub TerminateProcess(app_exe As String)
        Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = '" & app_exe & "'")
            Process.Terminate
        Next
    End Sub

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    Re: How can close any file by title description

    Thanks ChrisE

    But can you do it by Window Title

    For Example if you open Photoshop,

    i need when i open my program in vb, I want if found in the window title word Photoshop I want to close it.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    Re: How can close any file by title description

    same like this

    Code:
    Private Sub Command1_Click()
    
    Const WM_CLOSE = &H10
    
        Dim WinWnd As Long
    
        WinWnd = FindWindow(vbNullString, "Untitled - Notepad")
    
        If WinWnd <> 0 Then
            PostMessage WinWnd, WM_CLOSE, 0&, 0&
        'Else
            'MsgBox "No window of that name exists."
        End If
    End Sub


    But this code should put same Window Title Exactly, i no need if found same sentence Exactly
    I Need if found any word, For Example if found in window title Untitled i need close this exe

  10. #10
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: How can close any file by title description

    Again, I have to ask ... Why???

    What possible reason can you have for killing off a particular application that your User(s) may be quite legitimately using for their own purposes and who will not be best pleased to lose an entire morning's work because your application chose to kill it off.

    What are you trying to achieve here?
    Big Picture description, please, not the specific problem you're currently facing.

    Regards, Phill W.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    134

    Re: How can close any file by title description

    Hi Phill,

    i need close some Program by Window Title via my program,
    i want make my program to close some program, my client need like this.

  12. #12
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: How can close any file by title description

    That's the "specific problem". What's the "End Game" here?

    Is it to prevent a particular program from being run on somebody's machine?
    Is it to shut down a particular program so that it can be updated/ upgraded?
    Some other reason?

    > "my client need like this"

    Just because somebody tells you they want something, doesn't mean it's what they actually need.

    This is an "odd" thing for a VB program to do and, as soon as you get asked for something like this, you should be challenging the so-called "requirement" and try to root out what's actually needed.

    Regards, Phill W.

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