Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set a registry key based on logic from the computer name

Posted on 2013-06-12
2
Medium Priority
?
727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

670 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