Stuart_C Posted May 14, 2010 Posted May 14, 2010 Hi there, I need some script advice as I basically know nothing. I say "advice" something I can copy would be very helpfull I need a script that I can run at login that queries AD for the name (e.g. John S. Smith) of the user then adds/modifies that sting to a reg key. In this case HKCU\Software\Microsoft\Office\Common\UserInfo\UserName Help?
SYNACK Posted May 14, 2010 Posted May 14, 2010 (edited) I set it via the logon vbs script, actually for win2k3, but there may be more properties now. It does cause an msiexec installing bar to appear whilst logging on. Anyway, it's something like: Set ADSysInfo = CreateObject("ADSystemInfo") Set objUser = GetObject("LDAP://" & ADSysInfo.UserName) Sub SetOfficeUser On error Resume next Set objWord = CreateObject("Word.Application") objWord.UserName = objUser.givenName & " " & objUser.SN objWord.UserInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) objWord.Quit End Sub This script may do what you are after, not via the registry but will have a further look. Edited May 14, 2010 by SYNACK
SYNACK Posted May 14, 2010 Posted May 14, 2010 (edited) This looks as if it should work in the way that you want it to, I'm not hooked up to the domain here though so could not fully test it. Set ADSysInfo = CreateObject("ADSystemInfo") Set objUser = GetObject("LDAP://" & ADSysInfo.UserName) Set WshShell = WScript.CreateObject("WScript.Shell") regpath = "HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\" UsersName = objUser.givenName & " " & objUser.SN UsersInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) WshShell.RegWrite regpath & "UserName", UsersName, "REG_SZ" WshShell.RegWrite regpath & "UserInitials", UsersInitials, "REG_SZ" Explaination of VBS: (for easier searching) This script reads the first and last name of a users active directory (AD) logon account using LDAP then then enters these values into the UserName and UserInitials keys in the users registry. This solves the problem of users being prompted to enter their full names and initials when they first run a Microsoft Office application. It will error out if the users computer cannot contact a domain controller, add the line On error Resume next to the top of it if you want to suppress this error. Edited May 14, 2010 by SYNACK 1
Stuart_C Posted May 14, 2010 Author Posted May 14, 2010 Thanks for that. However... It just put's in blank values. Also is it going to pick the AD Displyname or their username? (I need to put in the former).
SYNACK Posted May 14, 2010 Posted May 14, 2010 (edited) It should pick up the values in the fistname and lastname box in their AD user account then put a space in between and commit it to the reg key. If the values are coming through blank it may either be having an issue reading them from AD or the firstname and lastname fields in AD may not set for the particular user that you are running it under. you may be able to do this: UsersName = objUser.displayName to put in the displayname instead of generating it from first and last but then making the initials if the other values are not present would be more difficult. Edited May 14, 2010 by SYNACK 1
Stuart_C Posted May 14, 2010 Author Posted May 14, 2010 (edited) You are OK. I figured out a fraction of a second before you posted it that the First name and surname are missing from MY AD account, and ofcourse I'm testing in that!!! Entries filled in and it works OK. P.s. is there a way to lower the case of the initials? Oh and if I put the error suppression in don't I need a "next" somewhere? When I put it in at the bottom it errors. Edited May 14, 2010 by Stuart_C
SYNACK Posted May 14, 2010 Posted May 14, 2010 No need for a next with the error suppression, VBS is a primitive beast and so the declaration will just continue until the script ends. You could convert the initials to lower case or upper case by using the lcase or ucase functions on the variable like this: lower case LCase(UsersInitials) or upper case UCase(UsersInitials) inserted under the UsersInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) line
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now