Set environment variables for a process

What is your problem actually? System.Environment.SetEnvironmentVariable changes the environment variables of the current process. If you want to change the variables of a process you create, just use the EnvironmentVariables dictionary property: var startInfo = new ProcessStartInfo(); // Sets RAYPATH variable to “test” // The new process will have RAYPATH variable created with “test” value … Read more

Run process as administrator from a non-admin application

You must use ShellExecute. ShellExecute is the only API that knows how to launch Consent.exe in order to elevate. Sample (.NET) Source Code In C#, the way you call ShellExecute is to use Process.Start along with UseShellExecute = true: private void button1_Click(object sender, EventArgs e) { //Public domain; no attribution required. ProcessStartInfo info = new … Read more

Running MSBuild programmatically

I would recommend stronlgy to go the official route via classes/interfaces in Microsoft.Build namespace. Microsoft uses this all over the place, so this should count for something… Esp. the class Microsoft.Build.Execution.BuildManager and the Singleton Microsoft.Build.Execution.BuildManager.DefaultBuildManager is what you are after to run a build task… source code examples: http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/ec95c513-f972-45ad-b108-5fcfd27f39bc/ Logging Build messages with MSBuild 4.0

.NET – WindowStyle = hidden vs. CreateNoWindow = true?

As Hans said, WindowStyle is a recommendation passed to the process, the application can choose to ignore it. CreateNoWindow controls how the console works for the child process, but it doesn’t work alone. CreateNoWindow works in conjunction with UseShellExecute as follows: To run the process without any window: ProcessStartInfo info = new ProcessStartInfo(fileName, arg); info.CreateNoWindow … Read more

Executing Batch File in C#

This should work. You could try to dump out the contents of the output and error streams in order to find out what’s happening: static void ExecuteCommand(string command) { int exitCode; ProcessStartInfo processInfo; Process process; processInfo = new ProcessStartInfo(“cmd.exe”, “/c ” + command); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; // *** Redirect the output *** … Read more

tech