Scripts Thread, Script Help - Query AD and add it to a reg key in Coding and Web Development; Hi there,
I need some script advice as I basically know nothing. I say "advice" something I can copy would ...
14th May 2010, 10:46 AM #1
Script Help - Query AD and add it to a reg key
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
14th May 2010, 03:03 PM #2
This script may do what you are after, not via the registry but will have a further look.
Originally Posted by mavhc
Last edited by SYNACK; 14th May 2010 at 03:07 PM.
14th May 2010, 03:21 PM #3
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
to the top of it if you want to suppress this error.
On error Resume next
Last edited by SYNACK; 14th May 2010 at 03:29 PM.
14th May 2010, 04:52 PM #4
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).
14th May 2010, 05:12 PM #5
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 05:17 PM.
14th May 2010, 05:31 PM #6
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 05:48 PM.
14th May 2010, 07:04 PM #7
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 case
inserted under the UsersInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) line
By Grommit in forum Windows
Last Post: 30th December 2009, 02:56 PM
By Edu-IT in forum Educational Software
Last Post: 13th November 2009, 03:31 PM
By Steven in forum Wireless Networks
Last Post: 5th October 2009, 09:24 AM
Last Post: 17th June 2008, 05:12 PM
By e_g_r in forum Windows
Last Post: 16th February 2007, 06:48 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)