Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Command to modify Registry entry

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
nappy_d
Asked:
nappy_d
1 Solution
 
Dirk KotteSECommented:
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
 
deroodeCommented:
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
 
CoralonCommented:
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
 
nappy_dAuthor Commented:
Thanks @Deroode.  That is just what I was looking for in the second option you provided.

Currently testing this and will follow-up :)
0
 
QlemoC++ DeveloperCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now