Solved

Set a registry key based on logic from the computer name

Posted on 2013-06-12
2
713 Views
Last Modified: 2013-06-14
I need to set a registry key value to be based upon the hostname of the Windows computer.

Our workstation names are generally as follows

AB983BVS01PC001
AB983BVS01PC002
AB983BVS01PC003
AB983BVS01PC004
AB983BVS02PC001
AB983BVS02PC002
AB983BVS02PC003
AB983BVS02PC004
etc.

I need to set a registry key value on each computer that is the first 12 Characters then adds 001 to it

e.g. on
AB983BVS02PC003 set the key to AB983BVS02PC001
AB983BVS55PC004 set the key to AB983BVS55PC001

The Registry key is

HKLM\Software\Application\
LeadComputer value AB983BVS02PC001

Can anyone suggest the best way to do this?

Thanks in advance!
0
Comment
Question by:aideb
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39243596
That's a one-liner in a batch script; you can roll that out as a startup (not logon!) script in a GPO applied to the machines in question:
reg add "HKLM\Software\Application" /v "LeadComputer" /t REG_SZ /d "%ComputerName:~0,12%001" /f

Open in new window

Assign computer startup scripts
http://technet.microsoft.com/en-us/library/cc779329(v=ws.10).aspx
0
 
LVL 2

Author Closing Comment

by:aideb
ID: 39247814
Excellent! Works a treat...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

808 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