Solved

Set a registry key based on logic from the computer name

Posted on 2013-06-12
2
700 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
Excellent! Works a treat...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

762 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

8 Experts available now in Live!

Get 1:1 Help Now