/build/static/layout/Breadcrumb_cap_w.png

Office 2010: REG_EXPAND_SZ and Variable Substring Selection?

I have found that Smart Ink Tools Addin for Office 2010 fails to load properly if the user is prompted to enter a Username and Userinitials when an Office product is first started. In the effort to prevent this prompt from happening, I have found that some registry values need to be present. Namely:

HKCU\Software\Microsoft\Office\Common\Userinfo\Company
HKCU\Software\Microsoft\Office\Common\Userinfo\Username
HKCU\Software\Microsoft\Office\Common\Userinfo\UserInitials



Configuring these values as a REG_EXPAND_SZ allows me to user the %username% variable as such:

reg add HKCU\Software\Microsoft\Office\Common\Userinfo /v Username /t REG_EXPAND_SZ /d "%%username%%" /f


Which ends up working great. When I start Office, the REG_EXPAND_SZ is expanded, and is replaced with a REG_SZ equal to the username.

However, I am having an issue with the UserInitials part. My attempt is:

reg add HKCU\Software\Microsoft\Office\Common\Userinfo /v Username /t REG_EXPAND_SZ /d "%%username:~0,2%%" /f

Which should get the first two characters of the Username variable. This works when testing in a cmd prompt, but when the REG_EXPAND_SZ ends up expanding, it only drops the first character in the resulting REG_SZ. I tried %username:~0,3% with the same results.

Does anybody know what is going on here?

UPDATE:

Tested with %username% as the value for both UserName and UserInitials, and found that it preserved the keys (not replacing them as I had thought). It seems that the issue is with regards to the substring selection idea, %username:~0,2%. If I have that configured as one of the values, it fails entirely and replaces my keys with the default keys, which is the username, and then the initials.  


0 Comments   [ + ] Show comments

Answers (1)

Answer Summary:
REG_EXPAND_SZ does not support substring functionality. Ended up copying batch file to system and creating a RunOnce value for the default user so that each user executes the script at first login.
Posted by: M P 11 years ago
Purple Belt
1

The below works for me with no issues.  I changed the values back to REG_SZ and used the UserName variable just like you wanted.

reg add HKCU\Software\Microsoft\Office\Common\Userinfo /v UserName /t REG_SZ /d %username% /f
reg add HKCU\Software\Microsoft\Office\Common\Userinfo /v UserInitials /t REG_SZ /d %username:~0,2% /f

Comments:
  • This works if you run the script in user context, but doesn't accomplish the same thing if you want to load the keys in the default user profile, which is what I was trying to accomplish. - muebel 11 years ago
    • Gotcha, checking on that now. - M P 11 years ago
    • After reviewing the documentation for REG_EXPAND_SZ values, you are not able to use the substring functionability. It looks like your best bet would be to use this command in a logon script in your environment or something similar.

      Quote:
      Note that this function does not support all the features that Cmd.exe supports. For example, it does not support %variableName:str1=str2% or %variableName:~offset,length%.

      Link:
      http://msdn.microsoft.com/en-us/library/windows/desktop/ms724265(v=vs.85).aspx - M P 11 years ago
      • Thanks! I even looked at the article you linked but failed to pick up on the relevant passage, indicating substring functionality as unsupported.

        I ended up having the script execute from RunOnce. - muebel 11 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ