Problems encountered in system. Diagnostics. process applications in. Net (continued)

Source: Internet
Author: User
After some research, I finally found out whether the previous article can be implemented even if the word instance is running. Article The required method in, Code As follows: String Temppath = System. environment. getenvironmentvariable ( " Temp " );
String Filename = Path. Combine (temppath, " Reasoning 01.doc " );
String Winwordpath =   "" ;

// Determine whether a word instance is running in the system.
Process [] wordprocesses = Process. getprocessesbyname ( " Winword " );
Foreach (Process In Wordprocesses)
{< br> debug. writeline (process. mainwindowtitle);
winwordpath = process. mainmodule. filename; // obtain the fully qualified name of winword.exe if any.
Break ;

Process wordprocess =   New Process ();

If (Winwordpath. Length >   0 ) // If a word instance is running, use the/W parameter to forcibly start the new instance and pass the file name as a parameter.
Wordprocess. startinfo. filename = Winwordpath;
Wordprocess. startinfo. useshellexecute =   False ;
Wordprocess. startinfo. Arguments = Filename +   " /W " ;
Else // If no word instance is running
Wordprocess. startinfo. filename=Filename;
Wordprocess. startinfo. useshellexecute= True;

Wordprocess. Start ();
Wordprocess. waitforexit (); // The current process is waiting until the word instance exits.
Wordprocess. Close ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.