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
Solved

Command to modify Registry entry

Posted on 2016-10-31
5
118 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
5 Comments
 
LVL 23

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 500 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 69

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

792 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