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

x
?
Solved

Command to modify Registry entry

Posted on 2016-10-31
5
Medium Priority
?
275 Views
Last Modified: 2016-11-07
I am looking to modify some workstation registries via a batch script.

What I would like to do is modify the the DevicePath of where to search for drivers.

Presently, HKLM\Software\Microsoft\Windows\Current Version has a key named DevicePath with a type REG_EXPAND_SZ

I would like to append to the existing data c:\drivers

Anyone have a method to accomplish this?

edit HKLM
0
Comment
Question by:nappy_d
[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
5 Comments
 
LVL 24

Expert Comment

by:Dirk Kotte
ID: 41867986
depends from script / shell / app you wish to use...
tell us more about your environment and possible the solution is more specific.
because you wish to change a HLM reg-key, your script has to run with administrator-privileges.

some examples:

from command shell:
c:\>reg /?   (reg query / reg add / ...)
http://ss64.com/nt/reg.html

powershell:
https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/12/weekend-scripter-use-powershell-to-easily-modify-registry-property-values/
https://msdn.microsoft.com/en-us/powershell/scripting/getting-started/cookbooks/working-with-registry-keys

vbs:
https://msdn.microsoft.com/en-us/library/aa384906(v=vs.85).aspx
http://ss64.com/vb/regwrite.html
0
 
LVL 19

Accepted Solution

by:
deroode earned 2000 total points
ID: 41868015
If you just want to add C:\Drivers to the existing path (which is default %Systemroot%\inf) you can get away with just a REG command:

REG add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v DevicePath /d %Systemroot%\inf;C:\Drivers /f

Open in new window


If however you expect that your workstations may have different values for the DevicePath entry, you want to append the C:\Drivers to the existing value:
set append=;C:\Drivers
set key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
set value=DevicePath
set oldVal=

for /F "skip=2 tokens=3" %%r in ('reg query %key% /v %value%') do set oldVal=%%r
echo previous=%oldVal%

set newVal=%oldVal%%append% 

reg add %key% /v %value% /d %newVal% /f

Open in new window

2
 
LVL 25

Expert Comment

by:Coralon
ID: 41868467
This should be pretty simple..

reg add "HKLM\Software\Microsoft\Windows\Current Version" /v DevicePath /d ^%SYSTEMROOT^%\inf;^%systemdrive^%\drivers; /t REG_EXPAND_SZ /f

Open in new window


The key is to escape the % symbols with the carets (^).. otherwise the values will be translated and you'll lose the benefit of REG_EXPAND_SZ.  (You can put in c:\drivers instead of ^%systemdrive^%\Drivers if you want to hard code it)

Coralon
0
 
LVL 32

Author Comment

by:nappy_d
ID: 41868833
Thanks @Deroode.  That is just what I was looking for in the second option you provided.

Currently testing this and will follow-up :)
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 41876163
In PowerShell:
$key, $name, $addvalue = 'HKLM:\Software\Microsoft\Windows\CurrentVersion', 'DevicePath', ';C:\Drivers\'
$value = (Get-ItemProperty $key).$name
if (';'+$value+';' -notlike "*$addvalue;*") { Set-ItemProperty $key $name -value ($value + $addvalue) }

Open in new window

This also checks that the path is not added already.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

715 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