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).
Updated 22-August-2009: I’ve updated the script to include support for Office 2007.
1; ----------------------------------------------------------------------------
2;
3; App Version: 2.3 (Change $appVersion when changing)
4; AutoIt Version: 3.0
5; Language: English
6; Platform: Windows 2000 / Windows XP / Windows Vista
7;
8; Script Function:
9; Get current user from Active Directory
10; Set current Office 2000, Office XP, or Office 2007 registered user.
11;
12; ----------------------------------------------------------------------------
13
14; ----------------------------------------------------------------------------
15; Set up our defaults and incldues
16; ----------------------------------------------------------------------------
17
18#Include
19
20$sFullName = "Full Name"
21$sInitials = "Initials"
22$sCompany = "Company"
23
24AutoItSetOption("MustDeclareVars", 1)
25;AutoItSetOption("TrayIconDebug", 1) ; DEBUG ONLY
26
27; ----------------------------------------------------------------------------
28; Setup Application Constants
29; ----------------------------------------------------------------------------
30
31Dim $appVersion = '2.3'
32
33Dim $FileOverwrite = 2
34Dim $LogFolder = @TempDir ; Change if necessary
35Dim $LogFile = "SetOfficeUser.log"
36
37; Set Company Name
38Dim $sCompany = "Generic Company"
39
40; Define Office Keys
41Dim $Office2KKey = "HKEY\_CURRENT\_USER\\Software\\Microsoft\\Office\\9.0\\Common\\UserInfo"
42Dim $OfficeXPKey = "HKEY\_CURRENT\_USER\\Software\\Microsoft\\Office\\11.0\\Common\\UserInfo"
43Dim $Office2K7Key = "HKEY\_CURRENT\_USER\\Software\\Microsoft\\Office\\Common\\UserInfo"
44
45; ----------------------------------------------------------------------------
46; Initialize Application Variables
47; ----------------------------------------------------------------------------
48
49Dim $objAD
50Dim $objUser
51
52Dim $sFullName
53Dim $sFirstName
54Dim $sLastName
55Dim $sInitials
56
57Dim $fHandle
58
59; ----------------------------------------------------------------------------
60; Create Our Log File
61; ----------------------------------------------------------------------------
62
63DirCreate($LogFolder)
64$fHandle = FileOpen($LogFolder & "\\" & $LogFile, $FileOverwrite)
65
66WriteLog("-")
67WriteLog("Set Office User Update Script")
68WriteLog("-")
69WriteLog(@CRLF)
70WriteLog("-")
71WriteLog("Script Version: " & $appVersion)
72WriteLog("Logged in User: " & @UserName)
73WriteLog("Operating System: " & @OSVersion)
74WriteLog("Company Defined: " & $sCompany)
75WriteLog("Script Location: " & @ScriptFullPath)
76WriteLog("Log Location: " & $LogFolder & "\\" & $LogFile)
77WriteLog("-")
78WriteLog(@CRLF)
79
80; ----------------------------------------------------------------------------
81; Get Active Directory Information
82; ----------------------------------------------------------------------------
83
84WriteLog("-")
85WriteLog("Entered 'Get Active Directory Information' Section")
86
87$objAD = ObjCreate("ADSystemInfo")
88$objUser = ObjGet("LDAP://" & $objAD.username & "")
89
90$sFirstName = $objUser.GivenName
91$sLastName = $objUser.LastName
92
93WriteLog("$sFirstName: " & $sFirstName)
94WriteLog("$sLastName: " & $sLastName)
95
96$sFullName = $sFirstName & " " & $sLastName
97$sInitials = StringLeft($sFirstName,1) & StringLeft($sLastName,1)
98
99If (StringLen($sFullName) <= 2) then
100 WriteLog ("ABORT! $SFullName Length is <= 2")
101 WriteLog ("-")
102 Exit (2)
103EndIf
104
105WriteLog("$sFullName: " & $sFullName)
106WriteLog("$sInitials: " & $sInitials)
107
108WriteLog("-")
109WriteLog(@CRLF)
110
111; ----------------------------------------------------------------------------
112; Update the Registry
113; ----------------------------------------------------------------------------
114
115WriteLog("-")
116WriteLog("Entered 'Update The Registry' Section")
117
118; Company doesn't seem to effect Microsoft Office Apps when Updated
119; May be able to change this in the Windows Installer section per MSKB 924461
120
121RegWrite($Office2KKey, "UserName", "REG\_BINARY", StringSpacer($sFullName) & chr(0) & chr(0))
122RegWrite($Office2KKey, "UserInitials", "REG\_BINARY", StringSpacer($sInitials) & chr(0) & chr(0))
123RegWrite($Office2KKey, "Company", "REG\_BINARY", StringSpacer($sCompany) & chr(0) & chr(0))
124
125RegWrite($OfficeXPKey, "UserName", "REG\_BINARY", StringSpacer($sFullName) & chr(0) & chr(0))
126RegWrite($OfficeXPKey, "UserInitials", "REG\_BINARY", StringSpacer($sInitials) & chr(0) & chr(0))
127RegWrite($OfficeXPKey, "Company", "REG\_BINARY", StringSpacer($sCompany) & chr(0) & chr(0))
128
129; Office 2007 doesn't seem to require the doublebyte characters.
130RegWrite($Office2K7Key, "UserName", "REG\_SZ", $sFullName)
131RegWrite($Office2K7Key, "UserInitials", "REG\_SZ", $sInitials)
132;RegWrite($Office2K7Key, "Company", "REG\_SZ", $sCompany)
133;RegWrite($Office2K7Key, "CompanyName", "REG\_SZ", $sCompany)
134
135WriteLog("User Keys Written to Windows Registry")
136
137WriteLog("-")
138WriteLog(@CRLF)
139
140; ----------------------------------------------------------------------------
141; END OF SCRIPT
142; ----------------------------------------------------------------------------
143
144WriteLog("-")
145WriteLog("END OF SCRIPT")
146WriteLog("-")
147
148Exit(0)
149
150; ----------------------------------------------------------------------------
151; Script Functions
152; ----------------------------------------------------------------------------
153
154Func StringSpacer($sString)
155
156 ; Adds a null character after each existing character of string.
157 ; Used to account for double byte characters in Registery Key.
158
159 Local $newString
160
161 $newString = ""
162 for $i = 1 to StringLen($sString)
163 $newString = $newString & StringMid($sString,$i,1) & chr(0)
164 next
165
166 return $newString
167
168EndFunc
169
170; ----------------------------------------------------------------------------
171
172Func WriteLog($sLine)
173 Local $DateTime
174 if ($sLine == "-") then $sLine = "------------------------------------------------------------------------------------------------"
175 If ($sLine == @CRLF) then
176 FileWriteLine ($fHandle, @CRLF)
177 Else
178 FileWriteLine ($fHandle, "\[" & \_now() & "\] " & $sLine)
179 EndIf
180EndFunc
No comments