Help properly setting up a System.Diagnostics.Process
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help properly setting up a System.Diagnostics.Process

  1. #1
    Join Date
    Apr 2010
    Posts
    131

    Help properly setting up a System.Diagnostics.Process

    Hi, and thanks for taking the time to read this.

    I'm faced with a problem I haven't run into before, and I can't seem to solve it on my own. I have to use my forms app (Program A - NET 3.5SP1) to open and manage another forms app (Program B, not mine).

    What I've done already works fine and dandy EXCEPT Program B reads some of its configuration settings from a text file in its install directory on startup. I've been modifying that text file prior to starting the process, but the changes haven't been read by the program.

    Finally, I figured out that Program B reads the text file fine if I start it manually, and if I put Program A into Program B's install directory and run it from there, it works fine as well. That has me thinking that System.Diagnostic.Process passes its own application/other environmental variables along to Program B.

    Since I can't acutally install Program A in PRogram B's directory, I'm hoping there's some way to get Program B to recognize its own install directory and be able to read the modified text file I put in it. MSDN seems to be telling me that System.Diagnostics.PorcessStartInfo.EnvironmentalVariables is read only.

    Any ideas how I can get Program B to think it's in the right place?

    I really appreciate any information or assistance you can provide. Please keep in mind I have almost zero experience with environmental variable formatting, etc. If you include 1 example for 1 environmental variable (maybe I only need to modify one I don't know) I'd REALLY appreciate it!!

    Thanks again!!!!

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,442

    Re: Help properly setting up a System.Diagnostics.Process

    Most likely, Process A is inadvertantly setting the CurrentDirectory of Process B.

    The reason is that when you specify only a file name (versus the full path of the file), the system uses a particular algorithm for locating the file. If you don't specify the full path, it creates it for you by using the CurrentDirectory, and then tries other paths like System32 and so on. Read more about this in CreateProcess api in msdn for the exact search method.

    To solve this problem is easy. Don't rely on CurrentDirectory which can change at any time and instead retrieve the path to the app and then form the full path to the file you wish to access (providing its located relative to your app).

    See my response in the following thread and also the code to GetAppFolder( ) method.

    http://www.codeguru.com/forum/showthread.php?t=509393

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center