-
Jan 18th, 2009, 04:34 AM
#1
Thread Starter
Frenzied Member
Terminate process by exe name
I would like some code that will terminate a process if i know its exe name.
-
Jan 18th, 2009, 04:45 AM
#2
Re: Terminate process by exe name
' Heres one way, example would close all running "calc.exe" files.
Code:
Private Sub Command1_Click()
TerminateProcess ("calc.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
-
Jan 18th, 2009, 04:58 AM
#3
Addicted Member
Re: Terminate process by exe name
Or, use the tskill.exe,
Code:
Shell "tskill appnamehere.exe"
-
Jan 18th, 2009, 02:31 PM
#4
Re: Terminate process by exe name
Posted this in your other thread and will work for both with the previous post mods I mentioned.
http://www.vbforums.com/showpost.php...73&postcount=8
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Jan 26th, 2009, 09:47 AM
#5
Addicted Member
Re: Terminate process by exe name
robdog888, i have try your code. it works for me, but got some problem. in my case i got three exe. your code work fine with one exe, but if in situation got randomly two exe or three exe running, termination will failed. how to change this part of code so it work correctly?
Code:
Dim blnRet As Boolean
blnRet = TerminateEXE("Woof.exe")
If Not blnRet Then
MsgBox "Terminate failed!"
End if
i thought can change like this but failed.
Code:
Dim blnRet As Boolean
blnRet = TerminateEXE("Woof.exe & notepad.exe & paint.exe")
If Not blnRet Then
MsgBox "Terminate failed!"
End if
-
Jan 26th, 2009, 11:35 AM
#6
Re: Terminate process by exe name
Are you saying that the exe names your program will start will be random exe names?
-
Jan 26th, 2009, 09:51 PM
#7
Addicted Member
Re: Terminate process by exe name
hack: no. i hv three fixed exe name. let say i hv exe1, exe2, exe3. if i open exe1 and close, the code work. but if i open exe 1 and exe2, then close, the code wouldnt work anf termination failed. so i mean how to change the code so that when randomly open those three exe (maybe 1 exe only, maybe 2 exe or all 3 exe), all can be terminated when closed.
-
Jan 27th, 2009, 11:51 AM
#8
Re: Terminate process by exe name
You need to check for all 3 and not just one exe.
Code:
Dim blnRet As Boolean
blnRet = TerminateEXE("Woof.exe")
If Not blnRet Then
MsgBox "Terminate failed!"
End if
blnRet = TerminateEXE("Meow.exe")
If Not blnRet Then
MsgBox "Terminate failed!"
End if
blnRet = TerminateEXE("Moo.exe")
If Not blnRet Then
MsgBox "Terminate failed!"
End if
But I wouldnt really say it should say failed since the exe may not be running. The fail or error should be dealt with in the called procedure
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Jan 27th, 2009, 10:26 PM
#9
Addicted Member
Re: Terminate process by exe name
robdog888, thanks a lot. i got it.
-
Feb 16th, 2014, 01:25 PM
#10
Lively Member
Re: Terminate process by exe name
Originally Posted by masterkert3
Or, use the tskill.exe,
Code:
Shell "tskill appnamehere.exe"
good idea... but it's unable to kill exe files that contains capital names or contains space in between. it seems it's not case sensitive
-
Feb 16th, 2014, 03:18 PM
#11
Re: Terminate process by exe name
Originally Posted by Mehdi Jazini
good idea... but it's unable to kill exe files that contains capital names or contains space in between. it seems it's not case sensitive
That is not true. try:
Code:
Shell ("TSKILL ""Exe NaMe Here""")
-
Feb 17th, 2014, 02:59 AM
#12
Lively Member
Re: Terminate process by exe name
Originally Posted by stum
That is not true. try:
Code:
Shell ("TSKILL ""Exe NaMe Here""")
tnx but:
1) i have tested your code in VB6 but it couldn't kill the task
2) i have opened MS-DOS and executed the following command in it, but i think the MS-DOS programmer used something like LCASE() function in TSKILL arguments! look at the result:
C:\>tskill "Connection Manager.exe"
Could not find process: connection manager.exe
C:\>
Last edited by Mahdi Jazini; Jan 6th, 2017 at 06:25 AM.
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
|