Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-26-2008, 6:08 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 20
Reputation: 16
suresh_ed is on a distinguished programming path ahead
Default Kill Specific process in task manager

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-26-2008, 7:41 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Have a look at usage for Process class. You should use CloseMainWindow method rather than Kill method.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-27-2008, 1:31 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 20
Reputation: 16
suresh_ed is on a distinguished programming path ahead
Default Kill process

I done that using system.management namespace.

Using that we can kill any specific process.

Thank you friend
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-27-2008, 8:59 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

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.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-29-2008, 5:57 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 20
Reputation: 16
suresh_ed is on a distinguished programming path ahead
Default Sorry for the late response

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 !!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 12-29-2008, 7:19 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

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.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 12-29-2008, 9:35 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 20
Reputation: 16
suresh_ed is on a distinguished programming path ahead
Default KillProcess class

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 12-29-2008, 10:51 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

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
Remember to use Code blocks when posting code, it makes the post readable. It is just one click of the Code button in message editor.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 12-29-2008, 11:26 PM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: May 2008
Posts: 20
Reputation: 16
suresh_ed is on a distinguished programming path ahead
Default Process class

It's working perfectly. Advance Happy New Year Wishes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 6:32 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.