Novell Home

Parse DS String Values into Binary for MS Office

Novell Cool Solutions: Trench
By Robert Stout

Digg This - Slashdot This

Posted: 23 Sep 2004
 

Updated with additional suggestion.

In the registry, MS Office user names and company names are saved in a funky kind of binary that cannot be replaced with string values from DS. For example:

HKCU\Software\Microsoft\Office\10.0\Common\UserInfo\Company
HKCU\Software\Microsoft\Office\10.0\Common\UserInfo\UserInitials
HKCU\Software\Microsoft\Office\10.0\Common\UserInfo\UserName

Solution

This launch script will parse out the string from DS into the binary that is needed for MS office for the properties of the document and in the About information. This works for ver. 10 and it should work for any -- you just need to change the reg path.

Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
 
sComputer = "."
hTree = HKEY_CURRENT_USER
sKey  = "Software\Microsoft\Office\10.0\Common\UserInfo"
sKey2 = "Software\Microsoft\Office\10.0\Common"
 
Set oRegistry =
GetObject("winmgmts:{impersonationLevel=impersonate}//"
& sComputer & "/root/default:StdRegProv")
 
sMethod = "CreateKey"
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
 
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
 
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
 
sMethod = "SetDWordValue"
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
 
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey2
oInParam.sValueName = "UserData"
oInParam.uValue = 1
 

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
 
y = 0
 
strFirstName = "%Given Name%"
strLastName = "%Surname%"
 
strFullName = strFirstName + " " + "%Surname%"
 
For x = 1 To Len(strFullName)
ReDim Preserve aValue(y)
aValue(y) = Asc(Mid(strFullName, x, 1))
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
y = y + 2
next
 
ReDim Preserve aValue(y)
aValue(y) = &h0
 
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
 
sMethod = "SetBinaryValue"
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
 
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = "UserName"
oInParam.uValue = aValue
 

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
 

y = 0
ReDim aValue(0)
 
strUserInitials = left(strFirstName,1) + left(strLastName,1)
 
For x = 1 To Len(strUserInitials)
ReDim Preserve aValue(y)
aValue(y) = Asc(Mid(strUserInitials, x, 1))
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
y = y + 2
next
 
ReDim Preserve aValue(y)
aValue(y) = &h0
 
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
 
oInParam.sValueName = "UserInitials"
oInParam.uValue = aValue
 
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)

 
 
y = 0
ReDim aValue(0)
strCompanyName = "%Company Name%"
 
For x = 1 To Len(strCompanyName)
ReDim Preserve aValue(y)
aValue(y) = Asc(Mid(strCompanyName, x, 1))
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
y = y + 2
next
 
ReDim Preserve aValue(y)
aValue(y) = &h0
 
ReDim Preserve aValue(y + 1)
aValue(y + 1) = &h0
 
oInParam.sValueName = "Company"
oInParam.uValue = aValue
 
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)

If you have any questions you may contact Robert at rstout@duesd.org

Additional Suggestions

Bryan Keadle

We have a single image for our Standard Load. We "import" the user's NDS information into the registry so that the user information reflects correctly the user information stored in NDS using a program I created called: OfficeUserInformation.exe

This program simply reads the user attributes: "Given Name", "SurName", and "Initials", converts them to the binary equivalent and populates the registry entries. We run this once for a user upon login.

This is particularly important to set these values to the user so that when users try to open a file from the network that is being used by another user, Office will report correctly which user has the file open instead of the generic user "Information Systems" that is contained within our standard load image.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell