using System.IO;
using System.Diagnostics;
public static bool AddOffice12UserInfo()
{
bool passed = false;
string[] commands = new string[5];
commands[0] = @"add HKCU\Software\Microsoft\Office\12.0\Common /v UserData /t REG_DWORD /d 1 /f";
commands[1] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v Company /t REG_SZ /d Microsoft /f";
commands[2] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v UserName /t REG_SZ /d TestRun /f";
commands[3] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v UserInitials /t REG_SZ /d t /f";
commands[4] = @"add HKCU\Software\Microsoft\Office\12.0\Common\General /v ShownOptIn /t REG_DWORD /d 00000001 /f";
for (int i = 0; i < commands.Length; i++)
{
bool temp = StartREG(commands[i]);
if (!temp)
{
return false;
}
}
passed = true;
return passed;
}
public static bool StartREG(string arguments)
{
bool passed = false;
int exitcode = -100;
try
{
string localpath = Path.Combine(System.Environment.GetEnvironmentVariable("SYSTEMROOT"), "system32");
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.EnableRaisingEvents = false;
myProcess.StartInfo.FileName = Path.Combine(localpath, "reg.exe");
myProcess.StartInfo.Arguments = arguments;
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
myProcess.WaitForExit();
exitcode = myProcess.ExitCode;
if (exitcode == 0)
{
passed = true;
}
else
{
Debug.WriteLine("reg exit code is::" + myProcess.ExitCode.ToString());
}
}
catch (Exception ex)
{
Debug.Fail(ex.Message, ex.StackTrace);
}
return passed;
}