-
Vb.Net launch/Close NotePad.exe,WORD.exe
Hi there,
Launching more than one sessions of NotePad.exe or WORD.exe using Vb.Net Component PROCESS is fine but having problem closing NotePad.exe or WORD.exe when more than one Session of NotePad.exe or WORD.exe are on display on Windows.
Here is the sample script to stop NotePad.exe or WORD.exe
Private Sub BtnWordStop_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnWordStop.Click
Try
With WordProcess
.StartInfo.FileName = "WinWord.exe"
.CloseMainWindow()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "WORD Stop Error")
End Try
End Sub
--------------------------------------
Private Sub BtnStop_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnStop.Click
'stop and close NotePad.exe
Try
With noteProcess
.StartInfo.FileName = "NotePad.exe"
.CloseMainWindow()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Note Pad Stop Error")
End Try
End Sub
Could someone please help me with sample script. Thanks.
Cheers,
Lennie
-
Something like this should work:
Code:
Sub KillProcess(ByVal strApp As String)
Try
Dim proc As Array = Process.GetProcessesByName(strApp)
For Each P As Process In proc
P.CloseMainWindow()
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
...joe
-
Hi Joe,
Thanks for the sample script.
I have tested it and was surprised that :-
For example I have more than one sessions of WINWORD.EXE on, instead of the script closing it down automatically one at a time but I have to click on the BTNWORDSTOP many times.
Is there a way to make it close all the WORD sessions logically instead of clicking on the BTNWORDSTOP continously.
Last edited by Lennie; 08-06-2009 at 06:16 PM.
Cheers,
Lennie
-
Sorry Lennie, it works as desired on my machine. How are you calling the procedure in the button_click?
...joe
-
Hi Joe,
Thanks for your response. If it's a single session it does work. But if there are more than one sessions only one session is closed instead of all closed automatically without continously clicking on the BTNWORDSTOP.
Being struggling the whole night till morning trying to work around it but in vain.
Here are the scripts that I used to test.
Private Sub BtnWordStop_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnWordStop.Click
FKillProcess ("WinWord")
End sub
Private Sub FKillProcess(Byval strApp)
try
Dim proc As Array = Process.GetProcessesByName(strApp)
For Each P As Process In proc
P.CloseMainWindow()
Next
Catch ex as exception
messagebox.show(ex.message)
End try
End sub
Last edited by Lennie; 08-06-2009 at 06:31 PM.
Cheers,
Lennie
-
Your right, it must be a word issue. I tested with notepad and it worked correctly
...joe
Similar Threads
-
By sathya_k_83 in forum .NET
Replies: 12
Last Post: 03-09-2010, 09:51 AM
-
Replies: 6
Last Post: 11-06-2002, 02:42 PM
-
By Michael Culley in forum .NET
Replies: 6
Last Post: 06-19-2002, 09:11 AM
-
By Tom Cabanski in forum .NET
Replies: 74
Last Post: 03-14-2001, 03:30 PM
-
By David Kroll in forum .NET
Replies: 33
Last Post: 02-13-2001, 10:23 PM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks