Test Automation Tips: “User Name” dialog after new install of Word (Christin Boyd, Bill Robertson)

Published 05 May 09 02:12 PM

We have a team of developers who focus entirely on writing test automation programs for the purpose of covering the huge matrix of test cases that Visual Studio requires.  We often configure new installs of Office and our automated tests need to deal with the special things that Office products do when you first run them after a new install.  For example, when you first run Microsoft Word after a new install, it prompts you to enter your name and initials in a dialog that looks like this:

clip_image002

Our talented SDET’s (Software Development Engineer in Test) use the following function in their automated tests to suppress this dialog:

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;
}

Let me know if these Test Automation samples are useful and we will try to publish more of these.

-Christin Boyd, Program Manager, Visual Studio and Bill Robertson, Software Development Engineer in Test, Visual Studio

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Test Automation Tips: ???User Name??? dialog after new install of Word (Christin Boyd, Bill Robertson) | Microsoft Share Point said on May 5, 2009 5:45 PM:

PingBack from http://microsoft-sharepoint.simplynetdev.com/test-automation-tips-%e2%80%9cuser-name%e2%80%9d-dialog-after-new-install-of-word-christin-boyd-bill-robertson/

# Samuel Jack said on May 6, 2009 9:06 AM:

Am I missing something here?

It appears that this code is just setting some registry keys. So why call out to reg.exe? Why not just use Registry classes in Microsoft.Win32?

Just a thought!

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About VSTO Team

This login represents the Visual Studio Tools for Office team. Many members of the team us this account for publishing technical blog posts.

This Blog

Syndication

Page view tracker