Solved

append a registry string from batch

Posted on 2001-06-30
7
3,215 Views
Last Modified: 2013-12-28
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?
0
Comment
Question by:b9frosty
7 Comments
 
LVL 1

Expert Comment

by:sp8ufn
ID: 6241337
Probably you have to use some programs from NT resource kit
regdmp.exe, regini.exe. Get the key with the regdmp.exe
into  file  

regdmp.exe \\hkey_local_machine\..... > the_file.txt

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
0
 

Author Comment

by:b9frosty
ID: 6241368
Sorry,  I would like to do this without any special software on the end user machine.
0
 
LVL 63

Accepted Solution

by:
SysExpert earned 100 total points
ID: 6241392
There are no tools on a standard machne to do this.
You either need to write a program to do this, or use a tool from somewhere, NT reskit, WSH,  VB, or a good installation program.

I hope this helps !

0
Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a trade show? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 10

Expert Comment

by:tonnybrandt
ID: 6241448
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
0
 
LVL 1

Expert Comment

by:Serverman2001
ID: 6241494
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
0
 

Author Comment

by:b9frosty
ID: 6242168
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.

0
 

Expert Comment

by:Kakoroat
ID: 20031470
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("WScript.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:{impersonationLevel=impersonate}!Win32_Process")      
      
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session 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.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, arrValueNames(i),strValue
               if (instr(ucase(strValue),"C:\docs\dev") = 0) then
                     wscript.echo "reg export ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"" " & backupfilename
                  'output = shell.run("reg export ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"" " & backupfilename,sw_hide,true)
                  extcode = shell.Create("reg export ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"" " & backupfilename, Null,IngProcessID)                  
                     oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,"Path"
                     oReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,"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.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
'                      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.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Path","C:\docs\dev"
end if
</script>
</job>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now