Friday, April 2, 2010

Problem launching an application in C# asking to set an Environment variable.

Recently I came acrross an issue where I am using C# Process class to launch an application located in Program files directory. The issue I found is after I called process.start() method a pop up came asking "Please set an environment variable required to run this process smoothly". Worst here is I had already set these environment variable for the application but still my script couldn't run though manualy launching this application has no issue.

Solution: set "process.StartInfo.EnvironmentVariables" will resolve this issue.

example:
Process procss = new Process();
procss.StartInfo.FileName = "Application path";
procss.StartInfo.Arguments = "";
procss.StartInfo.EnvironmentVariables.Add("Variable name", Environment.GetEnvironmentVariable("Variable Name", EnvironmentVariableTarget.Machine));
procss.Start();

No comments:

Post a Comment