{"id":287,"date":"2009-05-10T00:18:56","date_gmt":"2009-05-09T16:18:56","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/?p=287"},"modified":"2010-11-24T22:32:23","modified_gmt":"2010-11-24T14:32:23","slug":"automate-the-population-of-the-users-ms-office-credentials","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2009\/05\/10\/automate-the-population-of-the-users-ms-office-credentials-287","title":{"rendered":"Automate the population of the user&#8217;s MS Office Credentials"},"content":{"rendered":"<p>This script will add the user&#8217;s correct Username and UserInitials to the MS Office registry key to prevent the first time prompt when a user runs up a program in the Office suite.<\/p>\n<p>It has been specifically designed to populate the values for multiple versions of Office as per the arrVersions array. Please review the script below to understand how this works.<\/p>\n<p>Enjoy!<!--more--><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' This script will add the Users' correct Username and UserInitials to the MS Office\r\n' registry key to prevent the first time prompt when a user runs up a program in the\r\n' Office suite.\r\n\r\n' Note that all Office versions before 2007 (12.0) used a Binary value, hence the\r\n' reason for needing to use the ConvertStringToBinary() function.\r\n\r\n' It gets the username and initials in one of two ways:\r\n' 1) It first tries Active Directory to get the given and surname properties.\r\n' 2) If that fails, it derives the initials from the logged on username based on\r\n'    common naming standards.\r\n'    For Example:\r\n'             If the username is Jeremy.Saunders, the initials will be JS\r\n'             If the username is jsaunders, the initals will also be JS\r\n'    This is easy to change\/add\/modify should you be using a different naming standard\r\n'    that follows a different pattern.\r\n\r\n' Release 1.1 Modified by Jeremy@jhouseconsulting.com on 24th November 2010.\r\n' Written by Jeremy@jhouseconsulting.com on 19th April 2009.\r\n\r\nOption Explicit\r\n\r\nDim arrBinaryValue(), strUsername, strUserInitials, strTemp, intNumberOfChars, objWSHNetwork\r\nDim objShell, strComputer, objReg, strKeyRoot, strKeyPath, arrVersions, Version, return\r\nDim strUsernameInBinary, strUserInitialsInBinary, objSysInfo, strUserDN, objUserProperties\r\nDim blnDebug\r\n\r\nConst HKEY_CURRENT_USER = &amp;H80000001\r\n\r\n' ********************** Set these variables *****************************\r\n\r\n' Set this to True to help debug issues.\r\nblnDebug = False\r\n\r\n' Add the Office application versions you are using to the arrVersions array.\r\narrVersions = Array(&quot;10.0&quot;,&quot;11.0&quot;,&quot;12.0&quot;,&quot;14.0&quot;)\r\n' Note that...\r\n' - Office 2000 = 9.0\r\n' - Office XP\/2002 = 10.0\r\n' - Office 2003 = 11.0\r\n' - Office 2007 = 12.0\r\n' - Office 2010 = 14.0\r\n\r\n' ************************************************************************\r\n\r\nstrComputer = &quot;.&quot;\r\nstrUsername = &quot;&quot;\r\nstrUserInitials = &quot;&quot;\r\n\r\nSet objShell = WScript.CreateObject(&quot;WScript.Shell&quot;)\r\nSet objWSHNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)\r\nSet objReg = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\\\&quot; &amp; _\r\n  strComputer &amp; &quot;\\root\\default:StdRegProv&quot;)\r\n\r\nOn Error Resume Next\r\n' Get the user properties from Active Directory.\r\nSet objSysInfo = CreateObject(&quot;ADSystemInfo&quot;)\r\nIf Err.Number = 0 Then\r\n  strUserDN = objSysInfo.UserName\r\n  Set objUserProperties = GetObject(&quot;LDAP:\/\/&quot; &amp; strUserDN)\r\n  If Err.Number = 0 Then\r\n    strUsername = objUserProperties.givenName &amp; &quot; &quot; &amp; objUserProperties.SN\r\n    strUserInitials = Left(objUserProperties.givenName, 1) &amp; Left(objUserProperties.SN, 1)\r\n  Else\r\n    If blnDebug Then\r\n      wscript.echo &quot;Cannot Retrieve User Properties from Active Directory.&quot;\r\n    End If\r\n  End If\r\nElse\r\n  If blnDebug Then\r\n    wscript.echo &quot;Cannot Connect to Active Directory.&quot;\r\n  End If\r\nEnd If\r\nOn Error Goto 0\r\nErr.Clear\r\n\r\nIf strUsername=&quot;&quot; Then\r\n  strUsername = objWSHNetwork.UserName\r\n  If instr(strUsername, &quot;.&quot;) &gt; 0 Then\r\n    strTemp = Split(strUsername, &quot;.&quot;)\r\n    strUserInitials = ucase(Left(strTemp(0), 1)) &amp; ucase(Left(strTemp(1), 1))\r\n  Else\r\n    strUserInitials = ucase(Left(strUsername, 2))\r\n  End If\r\nEnd If\r\n\r\nIf blnDebug Then\r\n  wscript.echo &quot;The username is: &quot; &amp; strUsername &amp; vbcrlf &amp; _\r\n               &quot;The initials are: &quot; &amp; strUserInitials\r\nEnd If\r\n\r\nIf IsArray(arrVersions) Then\r\n  For Each Version in arrVersions\r\n    strKeyRoot = &quot;HKCU\\&quot;\r\n    strKeyPath = &quot;Software\\Microsoft\\Office\\&quot;\r\n\r\n    If Version = &quot;9.0&quot; OR Version = &quot;10.0&quot; OR Version = &quot;11.0&quot; Then\r\n\r\n      strKeyPath = &quot;Software\\Microsoft\\Office\\&quot; &amp; Version\r\n\r\n      If RegKeyExists(strKeyRoot &amp; strKeyPath) Then\r\n\r\n        If NOT RegKeyExists(strKeyRoot &amp; strKeyPath &amp; &quot;\\Common&quot;) Then\r\n          return = objReg.CreateKey (HKEY_CURRENT_USER, strKeyPath &amp; &quot;\\Common&quot;)\r\n        End If\r\n        If NOT RegKeyExists(strKeyRoot &amp; strKeyPath &amp; &quot;\\Common\\UserInfo&quot;) Then\r\n          return = objReg.CreateKey (HKEY_CURRENT_USER, strKeyPath &amp; &quot;\\Common\\UserInfo&quot;)\r\n        End If\r\n\r\n        strKeyPath = strKeyPath &amp; &quot;\\Common\\UserInfo&quot;\r\n\r\n        strUsernameInBinary = ConvertStringToBinary(strUsername)\r\n        objReg.SetBinaryValue HKEY_CURRENT_USER, strKeyPath, &quot;UserName&quot;, strUsernameInBinary\r\n\r\n        strUserInitialsInBinary = ConvertStringToBinary(strUserInitials)\r\n        objReg.SetBinaryValue HKEY_CURRENT_USER, strKeyPath, &quot;UserInitials&quot;, strUserInitialsInBinary\r\n\r\n      End If\r\n\r\n    Else\r\n\r\n      If RegKeyExists(strKeyRoot &amp; strKeyPath &amp; Version) Then\r\n\r\n        If NOT RegKeyExists(strKeyRoot &amp; strKeyPath &amp; &quot;\\Common&quot;) Then\r\n          return = objReg.CreateKey (HKEY_CURRENT_USER, strKeyPath &amp; &quot;\\Common&quot;)\r\n        End If\r\n        If NOT RegKeyExists(strKeyRoot &amp; strKeyPath &amp; &quot;\\Common\\UserInfo&quot;) Then\r\n          return = objReg.CreateKey (HKEY_CURRENT_USER, strKeyPath &amp; &quot;\\Common\\UserInfo&quot;)\r\n        End If\r\n\r\n        strKeyPath = strKeyPath &amp; &quot;\\Common\\UserInfo&quot;\r\n\r\n        objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, &quot;UserName&quot;, strUsername\r\n        objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, &quot;UserInitials&quot;, strUserInitials\r\n\r\n      End If\r\n    End If\r\n  Next\r\nEnd If\r\n\r\nSet objWSHNetwork = Nothing\r\nSet objShell = Nothing\r\nSet objReg = Nothing\r\nSet objSysInfo = Nothing\r\n\r\nwscript.quit(0)\r\n\r\nFunction ConvertStringToBinary(strString)\r\n  ReDim arrBinaryValue(len(strString) * 2 + 1)\r\n  For intNumberOfChars = 0 To Len(strString) - 1\r\n    If intNumberOfChars = 0 Then\r\n      arrBinaryValue(0) = Asc(Mid(strString, intNumberOfChars + 1, 1))\r\n      arrBinaryValue(1) = 0\r\n    Else\r\n      arrBinaryValue(intNumberOfChars * 2) = Asc(Mid(strString, intNumberOfChars + 1, 1))\r\n      arrBinaryValue(intNumberOfChars * 2 + 1) = 0\r\n    End If\r\n  Next\r\n  arrBinaryValue(Len(strString) * 2) = 0\r\n  arrBinaryValue(Len(strString) * 2 + 1) = 0\r\n  ConvertStringToBinary = arrBinaryValue\r\nEnd Function\r\n\r\nFunction RegKeyExists(ByVal sRegKey)\r\n' Returns True or False based on the existence of a registry key.\r\n  Dim sDescription, oShell\r\n  Set oShell = CreateObject(&quot;WScript.Shell&quot;)\r\n  RegKeyExists = True\r\n  sRegKey = Trim (sRegKey)\r\n  If Not Right(sRegKey, 1) = &quot;\\&quot; Then\r\n    sRegKey = sRegKey &amp; &quot;\\&quot;\r\n  End If\r\n  On Error Resume Next\r\n  oShell.RegRead &quot;HKEYNotAKey\\&quot;\r\n  sDescription = Replace(Err.Description, &quot;HKEYNotAKey\\&quot;, &quot;&quot;)\r\n  Err.Clear\r\n  oShell.RegRead sRegKey\r\n  RegKeyExists = sDescription &lt;&gt; Replace(Err.Description, sRegKey, &quot;&quot;)\r\n  On Error Goto 0\r\n  Set oShell = Nothing\r\nEnd Function\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This script will add the user&#8217;s correct Username and UserInitials to the MS Office registry key to prevent the first time prompt when a user runs up a program in the Office suite. It has been specifically designed to populate the values for multiple versions of Office as per the arrVersions array. Please review the &#8230; <a title=\"Automate the population of the user&#8217;s MS Office Credentials\" class=\"read-more\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2009\/05\/10\/automate-the-population-of-the-users-ms-office-credentials-287\" aria-label=\"Read more about Automate the population of the user&#8217;s MS Office Credentials\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[5],"tags":[132,134,133],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-msoffice","tag-userinitials","tag-username"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":6,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/287\/revisions\/297"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}