Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the value of registry key

Status
Not open for further replies.

omegabeta

Programmer
Aug 20, 2003
148
RO
Hi,

I want to change the value of registry key with another,
so that ...\open be changed in \open1. I've start with the following:

Dim WSHShell, valKey
Set WSHShell = WScript.CreateObject("WScript.Shell")

valKey = WSHShell.RegRead("HKEY_CLASESS_ROOT\VBSFile\Shell\open")

..but I get an error message:"Invalid root in registry key HKEY..."
I don't know what's wrong.
Could someone tell me how can I rename the open in open1 ?

Thanks
 
Have you tried this ?
valKey = WSHShell.RegRead("HKCR\VBSFile\Shell\open[highlight]\[/highlight]")


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It's OK. But valKey is &RUN. How can I rename the Open to Open1 ?
 
Hello omegabeta,

Rename a key is a 3-step process. It is to read all the values and subkeys'. Create the new key name and rebuild all the values and subkeys'. Then delete the original key. There would not be a rename per-se built-in functionality exposed.

In practice, the easiest is to export the key to .reg file. Do the parsing and modifying in the .reg file. Then import the modified .reg file. All can be done by script if so desired.

regards - tsuji
 
tsuji,

I didn't done this before.Can you give an example(code) ?
 
omegabeta,

Suppose original key be
[HKEY_CURRENT_USER\Enduser_testing]
where there may be subkeys under it. You rename it to:
[HKEY_CURRENT_USER\End-user_testing]
This is how you can do it.
Code:
orgkey="HKEY_CURRENT_USER\Enduser_testing"
renkey="HKEY_CURRENT_USER\End-user_testing"

orgcmdline="regedit /e " & regfilespec & " " & orgkey
rencmdline="regedit /s " & regfilespec

set wshshell=createobject("wscript.shell")
regfilespec=wshshell.currentdirectory & "\tmp.reg"

wshshell.run orgcmdline,,true

set fso=createobject("scripting.filesystemobject")
set ts=fso.opentextfile(regfilespec,1)
s=""
do while not ts.atendofstream
    t=ts.readline
    if left(t,1)<>"[" then
        if len(trim(t))=0 then s = s & vbcrlf else s = s & t & vbcrlf
    else
        u=replace(t,orgkey,renkey,1,-1,1)
        v=replace(t,"[","[-")
        s=s & v & vbcrlf & vbcrlf & u & vbcrlf
    end if
loop
ts.close
set ts=fso.opentextfile(regfilespec,2,true)
ts.write s
ts.close
set ts=nothing

wshshell.run rencmdline,, true

fso.deletefile regfilespec
set fso=nothing
set wshshell=nothing
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top