JSI Tip 7110. How do I set the Microsoft Office registered Company, UserName, and UserInitials in a batch?

When I first read Microsoft Knowledge Base article 816951, describing that an Office 2003 upgrade doesn't prompt for new user and company information, I was surprised that Microsoft had not described the registry entries, so that a solution could be scripted. When I discovered that the registry entries are binary values storing double-byte characters, I understood why they didn't.

I have scripted MSOfficeNameReg.bat to allow you to set the Company, UserName, and UserInitials. The syntax for using MSOfficeNameReg.bat is:

MSOfficeNameReg "Company Name" "User Name" "User Intials" OK


"Company Name" is the company name you wish to set. Quote marks are required if the name contains spaces.
"User Name"    is the user name that you wish to set. Quote marks are required if the name contains spaces.
"User Intials" is the user's initials that you wish to set. Te initials wouldn't normally contain spaces.
OK             is a call directed environment variable that will contain
               a Y if the process was successful, or an N if the process failed.
NOTE: MSOfficeNameReg.bat uses Reg.exe from the Windows 2000 Support Tools, or Reg.exe that is built into Windows XP and later.

NOTE: MSOfficeNameReg.bat uses Environment Variable Delayed Expansion.

NOTE: MSOfficeNameReg.bat should work on all versions of office that use the HKEY_CURRENT_USER\Software\Microsoft\Office\<version number>\Common\UserInfo key to store the Company, UserName, and UserInitials REG_BINARY data values. I have tested it with Office 2000 and Office 2002.

MSOfficeNameReg.bat contains:

@echo off
if \{%4\}==\{\} @echo Syntax: MSOfficeNameReg "Company Name" "User Name" "User Intials" OK&goto :EOF
set MSONR="%TEMP%\MSOfficeNameReg.reg"
if exist %MSONR% del /q %MSONR%
set Company=%1
set UserName=%2
Set UserInitials=%3
set Company=%Company:"=%
set UserName=%UserName:"=%
set UserInitials=%UserInitials:"=%
regedit /a %MSONR% "HKEY_CURRENT_USER\Software\Microsoft\Office"
set UserInfo=N
for /f "Tokens=*" %%u in ('findstr /i /l /c:\Common\UserInfo\] %MSONR%') do if "!UserInfo!" EQU "N" set UserInfo=%%u
if %UserInfo% EQU "N" @echo Microsoft Office registry key not found.&endlocal&set %4=N&goto :EOF
Set ExpKey=%UserInfo:\[=%
Set ExpKey=%ExpKey:\]=%
call :reg1>>nul 2>>&1
for /f "Tokens=*" %%T in ('type %MSONR%') do set line=%%T&call :parse
if "%FNDCONT%" EQU "Y" call :out
if exist %MSONR% del /q %MSONR%
endlocal&set %4=Y
goto :EOF
set line=%line:"=%
if /i "%line:~0,4%" EQU "TEMP" goto TMPFND
if "%FNDCONT%" NEQ "Y" goto :EOF
if "%line:~0,1%" EQU "\[" call :out&goto :EOF
set worktmp=%line:,\=%
if "%worktmp%" EQU "%line%" set work=%work%%worktmp%&call :out&goto :EOF
set work=%work%%line%
goto :EOF
if /i "%line:~0,11%" EQU "TEMPUserNam" goto TMPFNDOK
if /i "%line:~0,11%" EQU "TEMPCompany" goto TMPFNDOK
if /i "%line:~0,11%" EQU "TEMPUserIni" goto TMPFNDOK
if "%FNDCONT%" EQU "Y" call :out
goto :EOF
if "%FNDCONT%" EQU "Y" call :out
set work=%line:,\=%
if "%work%" NEQ "%line%" set FNDCONT=Y
set work=%work:TEMP=%
set work=%work:hex(7):=%
if "%FNDCONT%" EQU "Y" goto :EOF
call :out
goto :EOF
if /i "%work:~0,8%" EQU "Company=" set worktmp=%work:~8%&set name=Company&goto output
if /i "%work:~0,9%" EQU "UserName=" set worktmp=%work:~9%&set name=UserName&goto output
set worktmp=%work:~13%
set name=UserInitials
call :reg2>>nul 2>>&1
goto :EOF
REG ADD "%RegKey%" /v TEMPCompany /t REG_MULTI_SZ /d "%Company%" /F
REG ADD "%RegKey%" /v TEMPUserName /t REG_MULTI_SZ /d "%UserName%" /F
REG ADD "%RegKey%" /v TEMPUserInitials /t REG_MULTI_SZ /d "%UserInitials%" /F
regedit /e %MSONR% "%ExpKey%" 
REG DELETE "%RegKey%" /v TEMPCompany /f
REG DELETE "%RegKey%" /v TEMPUserName /f
REG DELETE "%RegKey%" /v TEMPUserInitials /f
goto :EOF
set worktmp=%worktmp:,=%
set worktmp=%worktmp:0000=00%
set worktmp=%worktmp:0000=00%
set worktmp=%worktmp:0000=00%
set worktmp=%worktmp:0000=00%
set worktmp=%worktmp:0000=00%0000
REG ADD "%RegKey%" /v %name% /t REG_BINARY /d %worktmp% /F

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.