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\Use rName
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.
Code: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
to the top of it if you want to suppress this error.Code:On error Resume next
Last edited by SYNACK; 14th May 2010 at 02:29 PM.
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).
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.
Last edited by SYNACK; 14th May 2010 at 04:17 PM.
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.
Last edited by Stuart_C; 14th May 2010 at 04:48 PM.
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:
or upper caseCode:LCase(UsersInitials)
inserted under the UsersInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) lineCode:UCase(UsersInitials)
There are currently 1 users browsing this thread. (0 members and 1 guests)