Automatically set Microsoft Office User Info based on LDAP query

In our network we have had a problem where a lot of our users never configured their Microsoft Office user details and simply accepted the defaults. In our case it was ‘Admin’ due to our SOE not accommodating for it.

Example of the data I am referring to:

The worst part about it is that in our day and age we are using sophisticated search systems that use Author fields, along with advanced features within Office like reviewing that include initials when commenting/editing documents.

My Solution

To resolve this problem I have successfully deployed the below VB script as a start up script which collects the user info via LDAP (Microsoft Active Directory in my case) and updates the word application. The word application is the reference application for this setting (to the other Office applications).

 

Simply paste the above code to a text file and save it as a VB script. From there you can simply double-click on it to test it, and once you are happy and satisfied that it works you can deploy it via a group policy or possibly load it up as a run-once on the default user profile of an SOE to populate the info.

Examples of where the data is used in Office Word:

Comments welcome, and if you find any improvements changes necessary please let me know.

Post implementation review

So far we have deployed it to a group base of 300 machines and it has been very successful. The script performs quickly and has not added much processing time at login (mind you our machines are current equipment). I have made this a login script for all users and it is performed every time they log in. I encountered a problem where clients that didnt have Word installed (for whatever reason) would come up with an error on the user. To combat this i simply addded the first line to continue processing on errors.

10 thoughts on “Automatically set Microsoft Office User Info based on LDAP query”

  1. I have a batch version as well:

    REM Get User's Display name
    for /f "tokens=2*" %%a in ('net user "%Username%" /domain ^| find /i "Full Name"') do set DisplayName=%NAME%
    REM Set User's display as current user in office
    reg add "HKCU\Software\Microsoft\Office\Common\UserInfo" /v "UserName" /t REG_SZ /d "%NAME%" /f

  2. My approach was almost the same.

    cls
    $adobj = “”
    $dom=”LDAP://OU=Users,OU=Corp,DC=CONTOSO,DC=LOCAL”
    $userName = $env:Username

    $root = new-object DirectoryServices.DirectoryEntry $dom
    $strFilter = “(&(objectCategory=User)(samaccountname=$userName))”
    $selector = new-object DirectoryServices.DirectorySearcher
    $selector.filter = $strFilter
    $selector.SearchRoot = $root
    $adobj = $selector.findone()

    $prop = $person.properties
    $initial = $($prop.initials)
    $displayName = $($prop.displayname)
    $sam = $($prop.samaccountname)

    $wshShell = new-object -comObject wscript.shell
    $wshShell.regWrite(“HKCU\Software\Microsoft\Office\Common\UserInfo\UserInitials”, $initial, “REG_SZ”)
    $wshShell.regWrite(“HKCU\Software\Microsoft\Office\Common\UserInfo\UserName”, $displayName, “REG_SZ”)

    • Hi Yann,
      Nice variant of script. Just keep in mind that the registry entry may differ depending on OS/Office architecture variant.
      Thanks for posting it!

      I just removed your personal LDAP info from the script just in case you forgot.
      Ivan

    • Hi Todd,
      Interesting to include it in the OCW (Office Configuration Wizard). If your clients are not on the network when they first log in the script wont execute. Maybe a combination of OCW and startup GPO would cover more ground.

      Thanks for the comment,
      Ivan

  3. Brilliant, exactly what i needed. I just added UPPER and lowercase string convertions to the script:

    objWord.UserName = Ucase(Left(objUser.givenName, 1)) & Lcase(Right(objUser.givenName, Len(objUser.givenName) – 1)) & ” ” & Ucase(Left(objUser.SN, 1)) & Lcase(Right(objUser.SN, Len(objUser.SN) – 1))

    objWord.UserInitials = Ucase(Left(objUser.givenName, 1)) & Ucase(Left(objUser.SN, 1))

    • Hi Buggen,
      Thank you for the addition – i will add it as a variation should others want to use it (and might not be sure where it goes in the script).

      I never did this as our AD has first letter capitalisation for those two fields.

Leave a Reply to Ivan DretvicCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

QR Code Business Card
%d bloggers like this: