The important point for this little post is the line:
VSSProcess.StartInfo.EnvironmentVariables.Add("SSDIR",_vssDBPath);
If I am not mistaken, this is going to set variables in your process only. This is ideal, you don't want to muck with the settings for ordinary users if you don't have to.
You can also import Kernel32.dll and call SetEnvironmentVariable but it's unmanaged and, frankly, I don' t like it!
Here's more code! Set VssExePath equal to the path to your ss.exe (C:\Program Files\Microsoft Visual Studio\VSS\win32\SS.EXE) and VssDBPath equal to the path to your VSS database (the directory in which you'll find srcsafe.ini) ps: I have had trouble with spaces in the url. Try mapping a drive if you also have trouble
public
{
Process VSSProcess =
VSSProcess.StartInfo.FileName = _vssExePath;
if(Environment.GetEnvironmentVariable("SSDIR")==null)
}
VSSProcess.StartInfo.Arguments = sArgumentsString;
VSSProcess.StartInfo.UseShellExecute =
VSSProcess.StartInfo.WorkingDirectory = LocalGetFilePath;
VSSProcess.StartInfo.RedirectStandardOutput =
VSSProcess.StartInfo.RedirectStandardError =
VSSProcess.Start();
VSSProcess.WaitForExit();
VSSProcess.Close();
VSSProcess.Dispose();