Vb.Net launch/Close NotePad.exe,WORD.exe


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Vb.Net launch/Close NotePad.exe,WORD.exe

  1. #1
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319

    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

  2. #2
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    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

  3. #3
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    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

  4. #4
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    Sorry Lennie, it works as desired on my machine. How are you calling the procedure in the button_click?

    ...joe

  5. #5
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319
    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

  6. #6
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    Your right, it must be a word issue. I tested with notepad and it worked correctly

    ...joe

Similar Threads

  1. Replies: 12
    Last Post: 03-09-2010, 09:51 AM
  2. Replies: 6
    Last Post: 11-06-2002, 02:42 PM
  3. Is VB.Net difficult or not - OR - How difficult?
    By Michael Culley in forum .NET
    Replies: 6
    Last Post: 06-19-2002, 09:11 AM
  4. Why I like VB.NET
    By Tom Cabanski in forum .NET
    Replies: 74
    Last Post: 03-14-2001, 03:30 PM
  5. VB.NET: 3 points of view
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center