Script to import Reg Key based on user name

Posted on 2007-10-11
Last Modified: 2008-01-09
I am looking for a script that can look at a list of user names and phone extensions, then if there is a match import a regkey into HKCU.  Is this possible?

It would look like this.
If username is jsmith then import key

Any help would be appreciated.


Question by:goodadmin
    LVL 38

    Expert Comment

    Please provide an example of the list and the registry entries you would want to import.  Are you wanting it to compare entries on the list with the name of the user who is currently logged in?

    Author Comment

    I don't have a list yet.  I need to import a RegKey that contains the user phone extension.  So the extension number is the value that I need to import, in this case each user would have a different value for the extension.  See below, my extension is "3366"


    LVL 38

    Expert Comment

    Ok, well assuming you have a comma-delimited list named phonelist.txt where the lines look like this:

    Then you could use the script below.  Note that the REG command isn't included with Windows 2000, so if it needs to run on 2000 clients then you'll need to place a copy of REG.EXE in the same location as the script.

    Paste the text below the line into a new file with a .cmd extension.

    @echo off

    set phonekey=HKCU\Software\Octel\Geneva\VoiceControl\VMCs\{F3F6095A-AF8C-11D1-84B8-00C04FA310F7}

    for /F "tokens=1,2 delims=," %%G in (phonelist.txt) do (
     if "%%G"=="%username%" reg add "%phonekey%" /v PhoneNumber /t REG_SZ /d "%%H" /f


    Author Comment

    This is exactly what I was looking for.  I've tested this and it works like a charm. One question, do I place the statement and text file in the Netlogon directory in order for this to work when the users login?

    LVL 38

    Accepted Solution

    You could either place them in Netlogon and call the .cmd file from the "Logon script" line in AD Users and Computers or create a Group Policy Object with an entry under the node User Configuration\Windows Settings\Scripts\Logon.

    The way the script is written, phonelist.txt must be located in the same directory as the .cmd file.

    Author Comment

    Thank You

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Several part series to implement Internet Explorer 11 Enterprise Mode
    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now