TechnicallyChris.com

Technical and Personal Ramblings of a Bostonian
  • Home
  • About Chris
  • Donate
  • Contact Chris
Home > Random Technology > Microsoft Office Registered User Setup via Script

Microsoft Office Registered User Setup via Script

May 4th, 2009
Goto comments Leave a comment

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

If you enjoyed this article or it helped you in any way, I’d appreciate it if you’d post a comment below to let me know. All code examples are for demonstration only and should be used at your own risk. I cannot accept liability for unexpected results.

Chris Random Technology Microsoft Office, Scripts

Comments (7) Trackbacks (0) Leave a comment Trackback
  1. Nico Michel
    August 21st, 2009 at 11:39 | #1
    Reply | Quote

    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

  2. Chris
    August 22nd, 2009 at 13:10 | #2
    Reply | Quote

    @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?

  3. Shogan
    October 5th, 2009 at 06:10 | #3
    Reply | Quote

    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.

  4. Steve
    February 1st, 2010 at 07:22 | #4
    Reply | Quote

    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?

  5. Rob Lerman
    March 1st, 2010 at 21:17 | #5
    Reply | Quote

    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!

  6. Chris
    March 2nd, 2010 at 00:54 | #6
    Reply | Quote

    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.

  7. Rob Lerman
    March 2nd, 2010 at 18:51 | #7
    Reply | Quote

    Chris, That worked great, many thanks!

  1. No trackbacks yet.
Subscribe to comments feed
Generating a List of Values in Excel (VBA) Running Railo Express on Vista using Start.bat
RSS feed
  • Google
  • Youdao
  • Xian Guo
  • Zhua Xia
  • My Yahoo!
  • newsgator
  • Bloglines
  • iNezha

Sponsored By

RoboForm: Learn more...Read my review of RoboForm here.

Recent Posts

  • Just Bought the Google Nexus One
  • Seven Things I’ve Liked About Windows 7 in Seven Day
  • What’s Happened to Customer Service (Part 2)?
  • What’s Happened to Customer Service (Part 1)?
  • Capturing S.M.A.R.T. Hard Disk Data from WMI with AutoIt
  • Adjusting DCOM Settings via Script
  • How to Manually Call the Google Cache
  • RoboForm & RoboForm2Go Product Review
  • Updated PingCell Function for Excel
  • Creating Hyperlinks in Word and Excel Longer than 256 Characters

Categories

  • ColdFusion
  • Firefox
  • Google Nexus One
  • IIS
  • McAfee EE / SafeBoot
  • Microsoft Windows
  • Oracle
  • Random Code
  • Random Technology
  • Sports and Recreation
  • Subversion
  • The Untechnological

Archives

  • January 2010
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • October 2007
  • September 2007
  • August 2007
  • January 2007
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006

Meta

  • Register
  • Log in
PageRank
Top WordPress
Copyright © 2006-2010 TechnicallyChris.com
Theme by mg12. Valid XHTML 1.1 and CSS 3.