I want to make a file that toggles a registry value.
I’m trying to make it get the value and then act based upon the results. I’m not too keen on console applications. The program just seems to hang. What am I doing wrong?
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.FileName = "c:\\windows\\syswow64\\cmd.exe";
psi.Arguments = "reg query HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\AD7Metrics\\Engine\\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2} /v ProgramProvider /s";
p.StartInfo = psi;
p.Start();
if (p.StandardOutput.ReadToEnd().Contains("3FFA64D1D639"))
psi.Arguments = "reg add HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\AD7Metrics\\Engine\\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2} /v ProgramProvider /d {170EC3FC-4E80-40AB-A85A-55900C7C70DE} /f";
else
psi.Arguments = "reg add HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\AD7Metrics\\Engine\\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2} /v ProgramProvider /d {4FF9DEF4-8922-4D02-9379-3FFA64D1D639} /f";
p.StartInfo = psi;
p.Start();
Get familiar with CMD.exe /c and /k switches.
And as commenter said there’s no reason to make it so complicated. If you really need external program (I see no reason), you can invoke reg.exe directly, without cmd.exe.