Microsoft Office Registered User Setup via Script
The following AutoIt script will allow you to set the Microsoft Office Registered User Name, Initials, and Company via a script by getting the name information from Active Directory and modifying the keys . This is useful in corporate environments where you don’t want it to have a generic name when you’re being told someone else has your file open.
To compile this script into an EXE that you can run, you’ll need to download the AutoIt compiler from this website. You’ll want to change Dim $sCompany = “Generic Company” to have your company name, although it doesn’t look like Office ever reads this key, it’s probably using your Windows company name instead.
Also, this script will update Microsoft Office 2000 (9.0) and XP (11.0), if you have other versions, add them under “; Define Office Keys“, and then add new RegWrite lines under “; Update the Registry“.
Notes:
- Assumes that characters are single byte and adds a null character to the end.
- Use the latest version of AutoIt to compile (problem with REG_BINARY in older versions).
Script is provided as is, with no warranty, support, or liability. Feel free to modify/distribute, I’d appreciate if you’d keep my name and website in the headers.
Updated 22-August-2009: I’ve updated the script to include support for Office 2007.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | ; ---------------------------------------------------------------------------- ; ; App Version: 2.3 (Change $appVersion when changing) ; AutoIt Version: 3.0 ; Language: English ; Platform: Windows 2000 / Windows XP / Windows Vista ; Author: Christopher <www.TechnicallyChris.com> ; ; Script Function: ; Get current user from Active Directory ; Set current Office 2000, Office XP, or Office 2007 registered user. ; ; ---------------------------------------------------------------------------- ; ---------------------------------------------------------------------------- ; Set up our defaults and incldues ; ---------------------------------------------------------------------------- #Include <Date.au3> $sFullName = "Full Name" $sInitials = "Initials" $sCompany = "Company" AutoItSetOption("MustDeclareVars", 1) ;AutoItSetOption("TrayIconDebug", 1) ; DEBUG ONLY ; ---------------------------------------------------------------------------- ; Setup Application Constants ; ---------------------------------------------------------------------------- Dim $appVersion = '2.3' Dim $FileOverwrite = 2 Dim $LogFolder = @TempDir ; Change if necessary Dim $LogFile = "SetOfficeUser.log" ; Set Company Name Dim $sCompany = "Generic Company" ; Define Office Keys Dim $Office2KKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Common\UserInfo" Dim $OfficeXPKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo" Dim $Office2K7Key = "HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo" ; ---------------------------------------------------------------------------- ; Initialize Application Variables ; ---------------------------------------------------------------------------- Dim $objAD Dim $objUser Dim $sFullName Dim $sFirstName Dim $sLastName Dim $sInitials Dim $fHandle ; ---------------------------------------------------------------------------- ; Create Our Log File ; ---------------------------------------------------------------------------- DirCreate($LogFolder) $fHandle = FileOpen($LogFolder & "\" & $LogFile, $FileOverwrite) WriteLog("-") WriteLog("Set Office User Update Script") WriteLog("-") WriteLog(@CRLF) WriteLog("-") WriteLog("Script Version: " & $appVersion) WriteLog("Logged in User: " & @UserName) WriteLog("Operating System: " & @OSVersion) WriteLog("Company Defined: " & $sCompany) WriteLog("Script Location: " & @ScriptFullPath) WriteLog("Log Location: " & $LogFolder & "\" & $LogFile) WriteLog("-") WriteLog(@CRLF) ; ---------------------------------------------------------------------------- ; Get Active Directory Information ; ---------------------------------------------------------------------------- WriteLog("-") WriteLog("Entered 'Get Active Directory Information' Section") $objAD = ObjCreate("ADSystemInfo") $objUser = ObjGet("LDAP://" & $objAD.username & "") $sFirstName = $objUser.GivenName $sLastName = $objUser.LastName WriteLog("$sFirstName: " & $sFirstName) WriteLog("$sLastName: " & $sLastName) $sFullName = $sFirstName & " " & $sLastName $sInitials = StringLeft($sFirstName,1) & StringLeft($sLastName,1) If (StringLen($sFullName) <= 2) then WriteLog ("ABORT! $SFullName Length is <= 2") WriteLog ("-") Exit (2) EndIf WriteLog("$sFullName: " & $sFullName) WriteLog("$sInitials: " & $sInitials) WriteLog("-") WriteLog(@CRLF) ; ---------------------------------------------------------------------------- ; Update the Registry ; ---------------------------------------------------------------------------- WriteLog("-") WriteLog("Entered 'Update The Registry' Section") ; Company doesn't seem to effect Microsoft Office Apps when Updated ; May be able to change this in the Windows Installer section per MSKB 924461 RegWrite($Office2KKey, "UserName", "REG_BINARY", StringSpacer($sFullName) & chr(0) & chr(0)) RegWrite($Office2KKey, "UserInitials", "REG_BINARY", StringSpacer($sInitials) & chr(0) & chr(0)) RegWrite($Office2KKey, "Company", "REG_BINARY", StringSpacer($sCompany) & chr(0) & chr(0)) RegWrite($OfficeXPKey, "UserName", "REG_BINARY", StringSpacer($sFullName) & chr(0) & chr(0)) RegWrite($OfficeXPKey, "UserInitials", "REG_BINARY", StringSpacer($sInitials) & chr(0) & chr(0)) RegWrite($OfficeXPKey, "Company", "REG_BINARY", StringSpacer($sCompany) & chr(0) & chr(0)) ; Office 2007 doesn't seem to require the doublebyte characters. RegWrite($Office2K7Key, "UserName", "REG_SZ", $sFullName) RegWrite($Office2K7Key, "UserInitials", "REG_SZ", $sInitials) ;RegWrite($Office2K7Key, "Company", "REG_SZ", $sCompany) ;RegWrite($Office2K7Key, "CompanyName", "REG_SZ", $sCompany) WriteLog("User Keys Written to Windows Registry") WriteLog("-") WriteLog(@CRLF) ; ---------------------------------------------------------------------------- ; END OF SCRIPT ; ---------------------------------------------------------------------------- WriteLog("-") WriteLog("END OF SCRIPT") WriteLog("-") Exit(0) ; ---------------------------------------------------------------------------- ; Script Functions ; ---------------------------------------------------------------------------- Func StringSpacer($sString) ; Adds a null character after each existing character of string. ; Used to account for double byte characters in Registery Key. Local $newString $newString = "" for $i = 1 to StringLen($sString) $newString = $newString & StringMid($sString,$i,1) & chr(0) next return $newString EndFunc ; ---------------------------------------------------------------------------- Func WriteLog($sLine) Local $DateTime if ($sLine == "-") then $sLine = "------------------------------------------------------------------------------------------------" If ($sLine == @CRLF) then FileWriteLine ($fHandle, @CRLF) Else FileWriteLine ($fHandle, "[" & _now() & "] " & $sLine) EndIf EndFunc |

Office 2007 stores user info in the following registry location “HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo”
It uses a String Value and not Binary Value I’ve tried the following all works Fine accept it adds only the user initial to the UserName field and not the user’s name and surname.
RegWrite($Office7KKey, “UserName”, “REG_SZ”, StringSpacer($sFullName) & chr(0) & chr(0))
RegWrite($Office7KKey, “UserInitials”, “REG_SZ”, StringSpacer($sInitials) & chr(0) & chr(0))
RegWrite($Office7KKey, “Company”, “REG_SZ”, StringSpacer($sCompany) & chr(0) & chr(0))
any idea what I need to change to get it working.
regards
@Nico Michel
I’ve updated the script to include support for Office 2007. It looks like you’re right, it is a string value instead of Binary in the new version, which also means we don’t need to use StringSpacer function to add the null characters after each byte.
If the new code doesn’t work for you, take a look at your log (feel free to post it as a comment) and we’ll see where the issue is. Perhaps it’s not being pulled correctly from Active Directory?
Chris, thanks tried this out and it works very well on terminal servers running Office 2003 and one running 2007. Will be adding to login script soon to update all user info in Word. No more open documents from unknown users!
Thanks again for the script.
Thanks, I used it to update my office 2003 suite but i have ms project 2007 installed and it seems to have left the company name alone in that. Does project use a different place to hold its company name?
How would I modify this script to change it from the full name for the user name field to a log in ID instead?
This is a very good script.
Thank you!
Steve: It seems that the Company Key gets ignored. There is an KB article referenced in the code that might help you update the company code. If the MS article works for MS Project, you could add that to the script as another RegWrite.
Rob: In the Update Registry section, replace “StringSpacer($sFullName)” with “StringSpacer(@UserName)” (no quotes) for Office 2000 & 2003/XP, and replace “$sFullName” with “@UserName” (no quotes) for Office 2007.
Chris, That worked great, many thanks!