Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Kill a process

Kill a process

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krishna19
    wrote on last edited by
    #1

    Hi all, We have a functionality that opens a word document on a button click . The user can enter any thing in the word document and it gets saved with a different name.The original document is closed. The problem is , every time the application is run, it opens a WINWORD.EXE in the processes tab of the task manager, which , after repeated executions of the project, add up to a large number.I cannot figure out why tjis is happening even as the word document is being closed after saving. So is there any way to close the process as soon as the document is saved with a differenty name? Thanks in anticipation

    V A 2 Replies Last reply
    0
    • K krishna19

      Hi all, We have a functionality that opens a word document on a button click . The user can enter any thing in the word document and it gets saved with a different name.The original document is closed. The problem is , every time the application is run, it opens a WINWORD.EXE in the processes tab of the task manager, which , after repeated executions of the project, add up to a large number.I cannot figure out why tjis is happening even as the word document is being closed after saving. So is there any way to close the process as soon as the document is saved with a differenty name? Thanks in anticipation

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      I have the same problem sometimes with Word 2003 when using outlook. If you use automation you'ld probably be able to use some function from the object model or something. If all else fails, look into the Process class. eg.: Process process = Process.GetCurrentProcess(); process.Kill(); hope this helps. Coulda, woulda, shoulda doesn't matter if you don't. :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig:

      K 1 Reply Last reply
      0
      • K krishna19

        Hi all, We have a functionality that opens a word document on a button click . The user can enter any thing in the word document and it gets saved with a different name.The original document is closed. The problem is , every time the application is run, it opens a WINWORD.EXE in the processes tab of the task manager, which , after repeated executions of the project, add up to a large number.I cannot figure out why tjis is happening even as the word document is being closed after saving. So is there any way to close the process as soon as the document is saved with a differenty name? Thanks in anticipation

        A Offline
        A Offline
        A Gharighi
        wrote on last edited by
        #3

        If you are using Interop dlls, so you should have used Word.Application object and the Documents collection to Add/Open a new Document. In this way, when you are done with the object, you can simple use Word.Application.Quit() method. It will close winword.exe automatically. Be sure you're not just openning the document and let it just be. Take care of that by events implementation. AISAC - An Intelligent Sense of A Computer http://aisac.wordpress.com -- modified at 14:29 Thursday 4th May, 2006

        K 1 Reply Last reply
        0
        • A A Gharighi

          If you are using Interop dlls, so you should have used Word.Application object and the Documents collection to Add/Open a new Document. In this way, when you are done with the object, you can simple use Word.Application.Quit() method. It will close winword.exe automatically. Be sure you're not just openning the document and let it just be. Take care of that by events implementation. AISAC - An Intelligent Sense of A Computer http://aisac.wordpress.com -- modified at 14:29 Thursday 4th May, 2006

          K Offline
          K Offline
          krishna19
          wrote on last edited by
          #4

          hi, Thanks for the reply.. I tried Word.Application.Quit().. It gave me the following error.. Reference to a non-shared member requires an object reference... I guess i will have to use process.kill()... Thanks..

          A 1 Reply Last reply
          0
          • V V 0

            I have the same problem sometimes with Word 2003 when using outlook. If you use automation you'ld probably be able to use some function from the object model or something. If all else fails, look into the Process class. eg.: Process process = Process.GetCurrentProcess(); process.Kill(); hope this helps. Coulda, woulda, shoulda doesn't matter if you don't. :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig:

            K Offline
            K Offline
            krishna19
            wrote on last edited by
            #5

            hi, Process proc =Process.GetCurrentProcess() Proc.Kill() is killing my application but not the winword.. Is there a way to identify the winword process uniquely and kill it? Thanks...

            V 1 Reply Last reply
            0
            • K krishna19

              hi, Process proc =Process.GetCurrentProcess() Proc.Kill() is killing my application but not the winword.. Is there a way to identify the winword process uniquely and kill it? Thanks...

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              You didn't read correctly :-). Look up the Process class on MSDN. This was just an example: Process proc =Process.GetCurrentProcess(); //is idd your own process Proc.Kill() You can find the process by name or by id. Coulda, woulda, shoulda doesn't matter if you don't. :beer:
                 :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig: :jig:

              1 Reply Last reply
              0
              • K krishna19

                hi, Thanks for the reply.. I tried Word.Application.Quit().. It gave me the following error.. Reference to a non-shared member requires an object reference... I guess i will have to use process.kill()... Thanks..

                A Offline
                A Offline
                A Gharighi
                wrote on last edited by
                #7

                For Word.Application.Quit I meant the path to the method, actually you should have an object like this: Word.Application wApp = new Word.Application(); Word.Document wDoc = wApp.Documents.Open("foo.doc"); ... wDoc.Close(); wApp.Quit(); AISAC - An Intelligent Sense of A Computer http://aisac.wordpress.com

                K 1 Reply Last reply
                0
                • A A Gharighi

                  For Word.Application.Quit I meant the path to the method, actually you should have an object like this: Word.Application wApp = new Word.Application(); Word.Document wDoc = wApp.Documents.Open("foo.doc"); ... wDoc.Close(); wApp.Quit(); AISAC - An Intelligent Sense of A Computer http://aisac.wordpress.com

                  K Offline
                  K Offline
                  krishna19
                  wrote on last edited by
                  #8

                  Thanks for the reply, I am using wDoc.Close() wApp.Quit() It is closing the document but not the associated winword.exe. After repeated runs of the application, i have a lot of winword.exe's running in the task manager. how to close the associated process after the document is saved and closed?? Thanks in anticipation

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups