Appending new path to registry value vbscript

obso1337
obso1337 used Ask the Experts™
on
I need a vbscript that can append c:\drivers to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DevicePath
Then it would be %SystemRoot%\inf;c:\drivers any help is appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Here you go:


Set oShell = CreateObject("WScript.Shell")
RegKey = "HKLM\Software\Microsoft\Windows\CurrentVersion\"
oShell.RegWrite RegKey & "DevicePath", oShell.RegRead(RegKey & "DevicePath") & ";c:\drivers"

Open in new window

Commented:
This one will make sure c:\drivers is not in the string before appending it.  This will prevent it from writing c:\drivers more than once:

 
Set oShell = CreateObject("WScript.Shell")
RegKey = "HKLM\Software\Microsoft\Windows\CurrentVersion\"
If InStr(LCase(oShell.RegRead(RegKey & "DevicePath")), "c:\drivers") = 0 Then oShell.RegWrite RegKey & "DevicePath", oShell.RegRead(RegKey & "DevicePath") & ";c:\drivers"

Open in new window

Author

Commented:
That doesn't append to the registry key. It doesn't give an error either running as admin.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

You can use this
Set WshShell = WScript.CreateObject("WScript.Shell")
str = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DevicePath")
Call WshShell.RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DevicePath", str & ";c:\drivers", "REG_SZ")

Open in new window

Commented:
I just tested it and it works using XP...

Author

Commented:
Works for XP, which is my main concern. Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial