-
Oct 23rd, 2017, 06:52 AM
#1
Thread Starter
Addicted Member
How can close any file by title description
Hello everyone,
How can close any file by title description.
Thanks
-
Oct 23rd, 2017, 07:21 AM
#2
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.
-
Oct 23rd, 2017, 07:55 AM
#3
Thread Starter
Addicted Member
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.
-
Oct 23rd, 2017, 10:39 AM
#4
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.
-
Oct 24th, 2017, 05:22 AM
#5
Thread Starter
Addicted Member
Re: How can close any file by title description
For Example
-
Oct 24th, 2017, 05:30 AM
#6
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.
-
Oct 24th, 2017, 05:46 AM
#7
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.
-
Oct 24th, 2017, 06:06 AM
#8
Thread Starter
Addicted Member
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.
-
Oct 24th, 2017, 06:27 AM
#9
Thread Starter
Addicted Member
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
-
Oct 24th, 2017, 09:09 AM
#10
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.
-
Oct 24th, 2017, 09:14 AM
#11
Thread Starter
Addicted Member
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.
-
Oct 24th, 2017, 09:21 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|