b9frosty
asked on
append a registry string from batch
I have a particular registry string that I want to first check if it exists, if not create it and give it a value or if it does exist, append info to the end of the string that is already there. How can this be done?
ASKER
Sorry, I would like to do this without any special software on the end user machine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Basically you just want it to be there. Whether it was there or not, you want it to be there in the end, as i understand your question.
So i suggest that you create that specific key/value on you own computer, and export the key to a reg file. Then you can just run the reg file with the command
start <name of regfile>
If you do want the info, whether it was there or no, had a value etc..., i agree with Sysexpert. You need an external program. To add to the list that Sysexpert has given you i can also suggest kix, which also should be able to do this.
Hope this helps
Tonny
So i suggest that you create that specific key/value on you own computer, and export the key to a reg file. Then you can just run the reg file with the command
start <name of regfile>
If you do want the info, whether it was there or no, had a value etc..., i agree with Sysexpert. You need an external program. To add to the list that Sysexpert has given you i can also suggest kix, which also should be able to do this.
Hope this helps
Tonny
can you not use kixTart its great for adding registry keys
just copy it to the Netlogon directory along with all the dlls a you then got yourself a great scripting language that will do all you ever wanted
http://www.kixtart.org/
Daz
just copy it to the Netlogon directory along with all the dlls a you then got yourself a great scripting language that will do all you ever wanted
http://www.kixtart.org/
Daz
ASKER
I have to agree. What I did was create a way of doing it in VB and made an EXE and then added it to my install script. This seems to work fine. Thanks for all the help.
I created a wsf file to back up, find, append and/or create the necessary registry settings. In my case, I wanted to append the value to the PATH, so that it would be permanent instead of temporarily changing the path in a command window. I made it so that I could re-run the wsf as necessary.
I left in some of the comments (I ran into a problem with creating a wscript.object, so I went to wmi). Also if you want to see what type of items are in the registry, I left that code in too. Enjoy.
<job>
<script language="vbscript">
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
strComputer = "."
dim backupfilename
dim mydatetime
dim mymonth
dim smymonth
dim myday
dim smyday
dim myhour
dim smyhour
dim mymin
dim smymin
dim mysec
dim smysec
dim shell
dim output
'set shell = Wscript.CreateObject("WScr ipt.Shell" )
mydatetime = now()
mymonth = month(mydatetime)
myday = day(mydatetime)
myhour = hour(mydatetime)
mymin = minute(mydatetime)
mysec = second(mydatetime)
if mymonth < 10 then
smymonth = "0" & mymonth
else
smymonth = mymonth
end if
if myday < 10 then
smyday = "0" & myday
else
smyday = myday
end if
if myhour < 10 then
smyhour = "0" & myhour
else
smyhour = myhour
end if
if mymin < 10 then
smymin = "0" & mymin
else
smymin = mymin
end if
if mysec < 10 then
smysec = "0" & mysec
else
smysec = mysec
end if
backupfilename = "C:\backupreg\" & year(mydatetime) & "-" & smymonth & "-" & smyday & "-" & smyhour & "-" & smymin & "-" & smysec & ".reg"
wscript.echo backupfilename
'wscript.quit
set shell = getobject("winmgmts:{imper sonationLe vel=impers onate}!Win 32_Process ")
Set oReg=GetObject("winmgmts:{ impersonat ionLevel=i mpersonate }!\\" & strComputer & "\root\default:StdRegProv" )
strKeyPath = "SYSTEM\CurrentControlSet\ Control\Se ssion Manager\Environment"
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
found = false
dim extcode
dim IngProcessID
For i=0 To UBound(arrValueNames)
wscript.echo arrValueNames(i)
if (arrValueNames(i) = "Path") then
found = true
oReg.GetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath, arrValueNames(i),strValue
if (instr(ucase(strValue),"C: \docs\dev" ) = 0) then
wscript.echo "reg export ""HKLM\SYSTEM\CurrentContr olSet\Cont rol\Sessio n Manager\Environment"" " & backupfilename
'output = shell.run("reg export ""HKLM\SYSTEM\CurrentContr olSet\Cont rol\Sessio n Manager\Environment"" " & backupfilename,sw_hide,tru e)
extcode = shell.Create("reg export ""HKLM\SYSTEM\CurrentContr olSet\Cont rol\Sessio n Manager\Environment"" " & backupfilename, Null,IngProcessID)
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyP ath,"Path"
oReg.SetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath,"Path" ,(strValue & ";C:\docs\dev")
end if
end if
' Wscript.Echo "Value Name: " & arrValueNames(i)
' Select Case arrValueTypes(i)
' Case REG_SZ
' Wscript.Echo "Data Type: String"
' Wscript.Echo
' Case REG_EXPAND_SZ
' Wscript.Echo "Data Type: Expanded String"
' strValueName = "UIHost"
' oReg.GetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath, _
' arrValueNames(i),strValue
' Wscript.Echo "Value: " & strValue
' Wscript.Echo
' Case REG_BINARY
' Wscript.Echo "Data Type: Binary"
' Wscript.Echo
' Case REG_DWORD
' Wscript.Echo "Data Type: DWORD"
' Wscript.Echo
' Case REG_MULTI_SZ
' Wscript.Echo "Data Type: Multi String"
' Wscript.Echo
' End Select
Next
if not found then
oReg.SetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath,"Path" ,"C:\docs\ dev"
end if
</script>
</job>
I left in some of the comments (I ran into a problem with creating a wscript.object, so I went to wmi). Also if you want to see what type of items are in the registry, I left that code in too. Enjoy.
<job>
<script language="vbscript">
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
strComputer = "."
dim backupfilename
dim mydatetime
dim mymonth
dim smymonth
dim myday
dim smyday
dim myhour
dim smyhour
dim mymin
dim smymin
dim mysec
dim smysec
dim shell
dim output
'set shell = Wscript.CreateObject("WScr
mydatetime = now()
mymonth = month(mydatetime)
myday = day(mydatetime)
myhour = hour(mydatetime)
mymin = minute(mydatetime)
mysec = second(mydatetime)
if mymonth < 10 then
smymonth = "0" & mymonth
else
smymonth = mymonth
end if
if myday < 10 then
smyday = "0" & myday
else
smyday = myday
end if
if myhour < 10 then
smyhour = "0" & myhour
else
smyhour = myhour
end if
if mymin < 10 then
smymin = "0" & mymin
else
smymin = mymin
end if
if mysec < 10 then
smysec = "0" & mysec
else
smysec = mysec
end if
backupfilename = "C:\backupreg\" & year(mydatetime) & "-" & smymonth & "-" & smyday & "-" & smyhour & "-" & smymin & "-" & smysec & ".reg"
wscript.echo backupfilename
'wscript.quit
set shell = getobject("winmgmts:{imper
Set oReg=GetObject("winmgmts:{
strKeyPath = "SYSTEM\CurrentControlSet\
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
found = false
dim extcode
dim IngProcessID
For i=0 To UBound(arrValueNames)
wscript.echo arrValueNames(i)
if (arrValueNames(i) = "Path") then
found = true
oReg.GetExpandedStringValu
if (instr(ucase(strValue),"C:
wscript.echo "reg export ""HKLM\SYSTEM\CurrentContr
'output = shell.run("reg export ""HKLM\SYSTEM\CurrentContr
extcode = shell.Create("reg export ""HKLM\SYSTEM\CurrentContr
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyP
oReg.SetExpandedStringValu
end if
end if
' Wscript.Echo "Value Name: " & arrValueNames(i)
' Select Case arrValueTypes(i)
' Case REG_SZ
' Wscript.Echo "Data Type: String"
' Wscript.Echo
' Case REG_EXPAND_SZ
' Wscript.Echo "Data Type: Expanded String"
' strValueName = "UIHost"
' oReg.GetExpandedStringValu
' arrValueNames(i),strValue
' Wscript.Echo "Value: " & strValue
' Wscript.Echo
' Case REG_BINARY
' Wscript.Echo "Data Type: Binary"
' Wscript.Echo
' Case REG_DWORD
' Wscript.Echo "Data Type: DWORD"
' Wscript.Echo
' Case REG_MULTI_SZ
' Wscript.Echo "Data Type: Multi String"
' Wscript.Echo
' End Select
Next
if not found then
oReg.SetExpandedStringValu
end if
</script>
</job>
regdmp.exe, regini.exe. Get the key with the regdmp.exe
into file
regdmp.exe \\hkey_local_machine\.....
check the required key with simple perl or kixtart script
and put/append required value to the file
and then run
regini.exe program which will put the key into the registry