+ Post New Thread
Results 1 to 7 of 7
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 ...
  1. #1

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,675
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45

    Script Help - Query AD and add it to a reg key

    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\Use rName

    Help?

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,986
    Thank Post
    850
    Thanked 2,653 Times in 2,253 Posts
    Blog Entries
    9
    Rep Power
    764
    Quote Originally Posted by mavhc View Post
    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.
    Last edited by SYNACK; 14th May 2010 at 02:07 PM.

  3. #3

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,986
    Thank Post
    850
    Thanked 2,653 Times in 2,253 Posts
    Blog Entries
    9
    Rep Power
    764
    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
    Code:
    On error Resume next
    to the top of it if you want to suppress this error.
    Last edited by SYNACK; 14th May 2010 at 02:29 PM.

  4. Thanks to SYNACK from:

    Stuart_C (14th May 2010)

  5. #4

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,675
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    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).

  6. #5

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,986
    Thank Post
    850
    Thanked 2,653 Times in 2,253 Posts
    Blog Entries
    9
    Rep Power
    764
    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.

  7. Thanks to SYNACK from:

    Stuart_C (14th May 2010)

  8. #6

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,675
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    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.

  9. #7

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,986
    Thank Post
    850
    Thanked 2,653 Times in 2,253 Posts
    Blog Entries
    9
    Rep Power
    764
    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
    Code:
    LCase(UsersInitials)
    or upper case
    Code:
    UCase(UsersInitials)
    inserted under the UsersInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1) line

SHARE:
+ Post New Thread

Similar Threads

  1. need .reg file or script please
    By Grommit in forum Windows
    Replies: 6
    Last Post: 30th December 2009, 01:56 PM
  2. LogIT 3 - Reg Key
    By Edu-IT in forum Educational Software
    Replies: 10
    Last Post: 13th November 2009, 02:31 PM
  3. Logon script .reg
    By Steven in forum Wireless Networks
    Replies: 17
    Last Post: 5th October 2009, 08:24 AM
  4. Parallels F9 key query
    By hmd01 in forum Mac
    Replies: 3
    Last Post: 17th June 2008, 04:12 PM
  5. script to change permissions on Reg Key
    By e_g_r in forum Windows
    Replies: 4
    Last Post: 16th February 2007, 05:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •