![]() |
Click here to advertise with us
|
|
|||||||
| VB.NET General Discussion VB.NET general discussion area |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I want to close a process named yandytex.exe in task manager.
yandytex doesn't have sdk for .net Please suggest how to close the process. Regards, Suresh |
|
||||
|
Have a look at usage for Process class. You should use CloseMainWindow method rather than Kill method.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
||||
|
WMI Win32_Process class and Terminate method doesn't allow you to try and close the other process gracefully, it does the same as Kill. A better option if you don't want to use the .Net Process class is to use SendMessage API with WM_Close message, but Process class is of course the easiest option.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
|||
|
Hello JohnH,
I am not using process class for opening that application. am using external script to open and use the application. I checked the .Net process class thing is that we have to add the application to the process class then only we can close or kill. Thanks for your suggestion !!! |
|
||||
|
That is not correct. You can use the Process class to list currently running processes, once you have the correct process reference you can ask it to close.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
|||
|
I am using the following function to kill the specific process. But it couldn't able to find the process to kill.
calling KillProcess("yandytex.exe") Dim prc() As Process Dim ERROR_FILE_NOT_FOUND As Integer = 2 Dim ERROR_ACCESS_DENIED As Integer = 5 Try prc = System.Diagnostics.Process.GetProcessesByName(Proc essName) Dim eprc As IEnumerator = prc.GetEnumerator eprc.Reset() While eprc.MoveNext Dim proc As Process = CType(eprc.Current, Process) proc.Kill() proc = Nothing End While eprc = Nothing prc = Nothing Catch e As System.ComponentModel.Win32Exception If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then 'MessageBox.Show(e.Message + ". Process not found.") Throw New UnauthorizedAccessException(e.Message & ". Process not found.") Else If e.NativeErrorCode = ERROR_ACCESS_DENIED Then ' Note that if your word processor might generate exceptions ' such as this, which are handled first. 'MessageBox.Show(e.Message + ". You do not have permission to kill this process.") Throw New UnauthorizedAccessException(e.Message & ". You do not have permission to kill this process.") End If End If End Try Please Suggest |
|
||||
|
Friendly names doesn't contain file extensions. I would rather use a For-Each loop:
Code:
For Each p As Process In Process.GetProcessesByName("notepad")
Try
If p.CloseMainWindow() Then
MessageBox.Show("nice process close")
Else
p.Kill()
MessageBox.Show("oops, had to kill it :(")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|