Problems wrapping pathman.exe Resource Kit tool

G

Guest

I have attempted to use some simple code to wrap execution of the pathman.exe
utility released with the Windows Resource Toolkit 2k3. The goal is to
update the PATH variable as needed. I have tried executing pathman.exe
directly and via a dynamically generated batch file via the
System.Diagnostics.Process class. Both result in pathman.exe hanging. If I
execute pathman.exe with the same arguments on the command-line or execute
the dynamically generated batch file on the command-line, there is no hang.
I am trying to do this under .NET 1.1 (VS 2k3) for the WinXP platform.

Is there a better way to update the PATH environment variable for the system
and user other than using pathman.exe? Any idea why the command hangs?

Here's one of the variations of code I was trying:

string tmpFile = Path.GetTempFileName() + ".bat";
File.Delete(tmpFile.Replace(".bat", ""));

string myPath = @"C:\Program Files\Someapp";

StreamWriter writer = new StreamWriter(new FileStream(tmpFile,
FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
writer.WriteLine("pathman.exe /as \"" + myPath + "\"");
writer.Flush();
writer.Close();
writer = null;

Process tmpProc = new Process();
tmpProc.StartInfo.FileName = "cmd";
tmpProc.StartInfo.UseShellExecute = false;
tmpProc.StartInfo.Arguments = "/C \"" + tmpFile + "\"";
tmpProc.Start();
tmpProc.WaitForExit();
tmpProc.Close();
tmpProc.Dispose();
File.Delete(tmpFile);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top