Registry - search & replace 
Author Message
 Registry - search & replace

What's the quickest way to implement a registry search and replace?  (IE.
all occurances of COLSRV1 with COLMAIL1)

I don't want to use REGFIND.EXE because the DLL's aren't installed on all
machines.

I don't know the specific key - it changes depending on machine.

It needs to work on Windows 98 & Windows 2000 (workstation).

It would need to do everything in less then 1/2 second. (OK, I'm flexible
on this one <G>)

Any ideas?



Sat, 20 Nov 2004 01:16:22 GMT  
 Registry - search & replace
regfind.exe in the reskit.....


Quote:

> What's the quickest way to implement a registry search and replace?  (IE.
> all occurances of COLSRV1 with COLMAIL1)

> I don't want to use REGFIND.EXE because the DLL's aren't installed on all
> machines.

> I don't know the specific key - it changes depending on machine.

> It needs to work on Windows 98 & Windows 2000 (workstation).

> It would need to do everything in less then 1/2 second. (OK, I'm flexible
> on this one <G>)

> Any ideas?



Sat, 20 Nov 2004 03:58:28 GMT  
 Registry - search & replace
Michael,

This could be very messy (and difficutl) to do with traditional methods.  You
will also find it to be a massive annoyance trying to process tons of dead
registry space.

Can you narrow it down a little bit? One way to do this - with CAREFUL checking
on what the results are - is to simply export data from, say, a user profile,
with regedit.  You can then do a search and replace on the file, save it, and
import back into the registry.  Here's a partial solution, going as far as the
export and then reading the file back in to memory.  Note that this is still a
little oversimplified; I think there will be problems with doing

regfile = "C:\Temp\orl.reg"
RegExport "HKEY_CURRENT_USER\Software", regfile
aReg = fRead(regfile)

Sub RegExport(sKey, Fil)
 ' Exports sKey to Fil
 Set Sh = CreateObject("WScript.Shell")
 Sh.Run "regedit /s /e " & Fil & " " & sKey,0,True
End Sub

Function fRead(FilePath)
 'Given the path to a file, will return entire contents
 With CreateObject("Scripting.FileSystemObject")._
  OpenTextFile(FilePath,1)
 fRead = .ReadAll: .Close
 End With
End Function


Quote:

> What's the quickest way to implement a registry search and replace?  (IE.
> all occurances of COLSRV1 with COLMAIL1)

> I don't want to use REGFIND.EXE because the DLL's aren't installed on all
> machines.

> I don't know the specific key - it changes depending on machine.

> It needs to work on Windows 98 & Windows 2000 (workstation).

> It would need to do everything in less then 1/2 second. (OK, I'm flexible
> on this one <G>)

> Any ideas?



Sat, 20 Nov 2004 05:19:36 GMT  
 Registry - search & replace
Not to be ungrateful, but referring to criteria 2 - WITHOUT using
REGFIND.EXE.

I'm looking for a VBS/WSH solution for a registry search & replace.

Quote:

>>regfind.exe in the reskit.....



>>> What's the quickest way to implement a registry search and replace?  (IE.
>>> all occurances of COLSRV1 with COLMAIL1)

>>> I don't want to use REGFIND.EXE because the DLL's aren't installed on all
>>> machines.

>>> I don't know the specific key - it changes depending on machine.

>>> It needs to work on Windows 98 & Windows 2000 (workstation).

>>> It would need to do everything in less then 1/2 second. (OK, I'm flexible
>>> on this one <G>)

>>> Any ideas?



Sat, 20 Nov 2004 05:25:45 GMT  
 Registry - search & replace
Whoops.  Didn't read that far.  But I am confused by what you mean by:

 "I don't want to use REGFIND.EXE because the DLL's aren't installed on all
machines"

Regfind.exe doesn't require any DLLs.  And it can query remote machines (9X
and NT).  If it doesn't find the search pattern it simply does nothing.

Or am I just totally not comprehending your objective.....?


Quote:
> Not to be ungrateful, but referring to criteria 2 - WITHOUT using
> REGFIND.EXE.

> I'm looking for a VBS/WSH solution for a registry search & replace.


> >>regfind.exe in the reskit.....



> >>> What's the quickest way to implement a registry search and replace?
(IE.
> >>> all occurances of COLSRV1 with COLMAIL1)

> >>> I don't want to use REGFIND.EXE because the DLL's aren't installed on
all
> >>> machines.

> >>> I don't know the specific key - it changes depending on machine.

> >>> It needs to work on Windows 98 & Windows 2000 (workstation).

> >>> It would need to do everything in less then 1/2 second. (OK, I'm
flexible
> >>> on this one <G>)

> >>> Any ideas?



Sat, 20 Nov 2004 06:16:49 GMT  
 Registry - search & replace
When I run REGFIND on most 98 machines I get: REFIND.EXE file is linked to
missing export NTDLL.DLL:RtlsubAuthoritySid.  My problem is I need a
solution that runs on both 98 & 2000 workstations.

In this case I need to substitute the Exchange server the clients are
looking at.  (ie. CIGNT3 => CIGMAIL).  Since some have profiles and the
exchange server location is in several different registry keys.

I wrote a VBS script that does a registry search and replace, but it too
has issues with 98 machines.

Quote:

>>Whoops.  Didn't read that far.  But I am confused by what you mean by:

>> "I don't want to use REGFIND.EXE because the DLL's aren't installed on all
>>machines"

>>Regfind.exe doesn't require any DLLs.  And it can query remote machines (9X
>>and NT).  If it doesn't find the search pattern it simply does nothing.

>>Or am I just totally not comprehending your objective.....?



>>> Not to be ungrateful, but referring to criteria 2 - WITHOUT using
>>> REGFIND.EXE.

>>> I'm looking for a VBS/WSH solution for a registry search & replace.


>>> >>regfind.exe in the reskit.....



>>> >>> What's the quickest way to implement a registry search and replace?
>>(IE.
>>> >>> all occurances of COLSRV1 with COLMAIL1)

>>> >>> I don't want to use REGFIND.EXE because the DLL's aren't installed on
>>all
>>> >>> machines.

>>> >>> I don't know the specific key - it changes depending on machine.

>>> >>> It needs to work on Windows 98 & Windows 2000 (workstation).

>>> >>> It would need to do everything in less then 1/2 second. (OK, I'm
>>flexible
>>> >>> on this one <G>)

>>> >>> Any ideas?



Sun, 21 Nov 2004 04:43:30 GMT  
 Registry - search & replace
I'm trying to replace all occurances of my Exchange server with an updated
server name (ie. CIGNT3 => CIGMAIL) without having to touch each machine.  I
wrote a VBS script that work GREAT on 2000 machines, but it generates the
error:

"Microsoft VBScript runtime error: File name or class name not found during
Automation operation: 'getobject'"

when I try to run it with CSCRIPT on 98 machines (even thought the 98 machine
reports that the CSCRIPT version is 5.6).

Obviously it's the Set objRegistry =
getobject("winmgmts:root\default:stdregprov") line.  I guess I don't understand
the differences between pure WSH and VBS.  Any help?  

NOTE: code best viewed with non-proportional/fixed pitch font
'******************************* Code follows *************************

option explicit

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Dim objRegistry
dim intTotalMatch

    intTotalMatch = 0

    Set objRegistry = getobject("winmgmts:root\default:stdregprov")

    wscript.echo "Searching ... HKEY_USERS"
    call SearchReplace(HKEY_USERS, _
                       "", _
                       objRegistry, _
                       "COLNTSRV3", _
                       "CIGMAIL", _
                       intTotalMatch)

    wscript.echo "Searching ... HKEY_CURRENT_USER"
    call SearchReplace(HKEY_CURRENT_USER, _
                       "Software\Microsoft\Windows NT\CurrentVersion\Windows
Messaging Subsystem\Profiles\MS Exchange Settings", _
                       objRegistry, _
                       "COLNTSRV3", _
                       "CIGMAIL", _
                       intTotalMatch)

    Set objRegistry = Nothing

    if intTotalMatch = 0 then
        wscript.echo "TotalMatches: None Found"
    else
        wscript.echo "TotalMatches: " & inttotalmatch
    end if

         wscript.quit

'*************************************************************************
' Search and Replace
'*************************************************************************
function SearchReplace(lngHive, _
                       strKey, _
                       objRegistry, _
                       strSearch, _
                       strReplace, _
                       intMatchCount)

const REG_SZ        = 1
const REG_EXPAND_SZ = 2
const REG_BINARY    = 3
const REG_DWORD     = 4
const REG_MULTI_SZ  = 7

Dim strSubKey
dim strValue
dim strFullKey
dim strName
dim strMultiStrings
dim strThisValue
dim arrNames
dim arrTypes
dim arrTypeNames
Dim arrSubKeys
dim arrBinary
dim intX
dim intIndex
dim lngReturn
dim lngDWORD

    arrTypeNames = array("","REG_SZ","REG_EXPAND_SZ","REG_BINARY", _
                         "REG_DWORD","","","REG_MULTI_SZ")

    If objRegistry.EnumKey(lngHive, strKey, arrSubKeys) = 0 Then

        For Each strSubKey In arrSubKeys

            strFullKey = BackSlash(strKey, TRUE) & strSubKey

            call SearchReplace(lngHive, _
                               strFullKey, _
                               objRegistry, _
                               strSearch, _
                               strReplace, _
                               intMatchCount)

            'at this point we're at the top, we need to
            'get a list of the values

            lngReturn = objRegistry.EnumValues(lngHive, _
                                               strFullKey, _
                                               arrNames, _
                                               arrTypes)

            If (lngReturn = 0) And (Err.Number = 0) Then

                For intIndex = 0 To UBound(arrNames)

                    'we're only checking the REG_SZ values
                    Select Case arrTypes(intIndex)

                        Case REG_SZ

                            lngReturn = objRegistry.GetStringValue(lngHive, _
                                                                 strFullKey, _

arrNames(intIndex),_
                                                                 strValue)
                                                                         'the default named value
                            If arrNames(intIndex) = "" Then
                                arrNames(intIndex) =  "default"
                            End If

                    End Select

                    if ucase(strValue) = ucase(strSearch) then

                                                                '** NOTE: I'll impletment a write, when everything
                                                                'else is working.
                         'call wshShell.RegWrite(strFullKey, _
                                                 strReplace, _                  
                                                                                                                                 arrTypes(intIndex))
                         intMatchCount = cint(intMatchCount) + 1

                    end if

                Next

             end if

        Next

    End If

End function

'*************************************************************************
' Make sure a backslash exists, if wanted
'*************************************************************************
function BackSlash(strTemp, blnForceBS)

    if len(strTemp) > 0 then
        if blnForceBS then
            if right(strTemp,1) <> "\" then 'add it
                strTemp = strTemp & "\"    
            end if
        else
            if right(strTemp,1) = "\" then 'get rid of it
                strTemp = left(strtemp,len(strtemp) - 1)
            end if
        end if
    end if

    BackSlash = strTemp

end function



Sun, 21 Nov 2004 04:58:12 GMT  
 Registry - search & replace
The problem you have is that WMI is not installed on the Win9x machines.  You
*could* install it on them, but that means touching all of them anyway.

Are the affected values in the same location in the registry from machine to
machine on Win9x? A simple RegWrite could solve your problem if so.


Quote:
> I'm trying to replace all occurances of my Exchange server with an updated
> server name (ie. CIGNT3 => CIGMAIL) without having to touch each machine.  I
> wrote a VBS script that work GREAT on 2000 machines, but it generates the
> error:

> "Microsoft VBScript runtime error: File name or class name not found during
> Automation operation: 'getobject'"

> when I try to run it with CSCRIPT on 98 machines (even thought the 98 machine
> reports that the CSCRIPT version is 5.6).

> Obviously it's the Set objRegistry =
> getobject("winmgmts:root\default:stdregprov") line.  I guess I don't
understand
> the differences between pure WSH and VBS.  Any help?

> NOTE: code best viewed with non-proportional/fixed pitch font
> '******************************* Code follows *************************

> option explicit

> Const HKEY_CLASSES_ROOT = &H80000000
> Const HKEY_CURRENT_USER = &H80000001
> Const HKEY_LOCAL_MACHINE = &H80000002
> Const HKEY_USERS = &H80000003

> Dim objRegistry
> dim intTotalMatch

>     intTotalMatch = 0

>     Set objRegistry = getobject("winmgmts:root\default:stdregprov")

>     wscript.echo "Searching ... HKEY_USERS"
>     call SearchReplace(HKEY_USERS, _
>                        "", _
>                        objRegistry, _
>                        "COLNTSRV3", _
>                        "CIGMAIL", _
>                        intTotalMatch)

>     wscript.echo "Searching ... HKEY_CURRENT_USER"
>     call SearchReplace(HKEY_CURRENT_USER, _
>                        "Software\Microsoft\Windows NT\CurrentVersion\Windows
> Messaging Subsystem\Profiles\MS Exchange Settings", _
>                        objRegistry, _
>                        "COLNTSRV3", _
>                        "CIGMAIL", _
>                        intTotalMatch)

>     Set objRegistry = Nothing

>     if intTotalMatch = 0 then
>         wscript.echo "TotalMatches: None Found"
>     else
>         wscript.echo "TotalMatches: " & inttotalmatch
>     end if

> wscript.quit

> '*************************************************************************
> ' Search and Replace
> '*************************************************************************
> function SearchReplace(lngHive, _
>                        strKey, _
>                        objRegistry, _
>                        strSearch, _
>                        strReplace, _
>                        intMatchCount)

> const REG_SZ        = 1
> const REG_EXPAND_SZ = 2
> const REG_BINARY    = 3
> const REG_DWORD     = 4
> const REG_MULTI_SZ  = 7

> Dim strSubKey
> dim strValue
> dim strFullKey
> dim strName
> dim strMultiStrings
> dim strThisValue
> dim arrNames
> dim arrTypes
> dim arrTypeNames
> Dim arrSubKeys
> dim arrBinary
> dim intX
> dim intIndex
> dim lngReturn
> dim lngDWORD

>     arrTypeNames = array("","REG_SZ","REG_EXPAND_SZ","REG_BINARY", _
>                          "REG_DWORD","","","REG_MULTI_SZ")

>     If objRegistry.EnumKey(lngHive, strKey, arrSubKeys) = 0 Then

>         For Each strSubKey In arrSubKeys

>             strFullKey = BackSlash(strKey, TRUE) & strSubKey

>             call SearchReplace(lngHive, _
>                                strFullKey, _
>                                objRegistry, _
>                                strSearch, _
>                                strReplace, _
>                                intMatchCount)

>             'at this point we're at the top, we need to
>             'get a list of the values

>             lngReturn = objRegistry.EnumValues(lngHive, _
>                                                strFullKey, _
>                                                arrNames, _
>                                                arrTypes)

>             If (lngReturn = 0) And (Err.Number = 0) Then

>                 For intIndex = 0 To UBound(arrNames)

>                     'we're only checking the REG_SZ values
>                     Select Case arrTypes(intIndex)

>                         Case REG_SZ

>                             lngReturn = objRegistry.GetStringValue(lngHive, _
>                                                                  strFullKey, _

> arrNames(intIndex),_
>                                                                  strValue)
> 'the default named value
>                             If arrNames(intIndex) = "" Then
>                                 arrNames(intIndex) =  "default"
>                             End If

>                     End Select

>                     if ucase(strValue) = ucase(strSearch) then

> '** NOTE: I'll impletment a write, when everything
> 'else is working.
>                          'call wshShell.RegWrite(strFullKey, _
>                                                  strReplace, _
> arrTypes(intIndex))
>                          intMatchCount = cint(intMatchCount) + 1

>                     end if

>                 Next

>              end if

>         Next

>     End If

> End function

> '*************************************************************************
> ' Make sure a backslash exists, if wanted
> '*************************************************************************
> function BackSlash(strTemp, blnForceBS)

>     if len(strTemp) > 0 then
>         if blnForceBS then
>             if right(strTemp,1) <> "\" then 'add it
>                 strTemp = strTemp & "\"
>             end if
>         else
>             if right(strTemp,1) = "\" then 'get rid of it
>                 strTemp = left(strtemp,len(strtemp) - 1)
>             end if
>         end if
>     end if

>     BackSlash = strTemp

> end function



Sun, 21 Nov 2004 05:14:53 GMT  
 Registry - search & replace
After some research I realized the problem with WMI myself.  And you've hit the
nail on the head - if I touch each machine to install WMI then I might as well
fix the server issue.

the problem is NO, the keys aren't necessarily the same for all machines.  The
code I included works GREAT on 2000 machines, so I think that my solution.  For
the 98 machines I'll recompare the keys, there are only 2 or 3 (out of 21) that
differ machine to machine.  I'll try changing the common keys and see (pray)
that the unique keys will be cascadedly updated by Outlook when it runs.

BTW:  Is there a pure WSH method for determining OS.  (ie. WSCRIPT.ENVIRONMENT
???)


Quote:
>>The problem you have is that WMI is not installed on the Win9x machines.  You
>>*could* install it on them, but that means touching all of them anyway.

>>Are the affected values in the same location in the registry from machine to
>>machine on Win9x? A simple RegWrite could solve your problem if so.



>>> I'm trying to replace all occurances of my Exchange server with an updated
>>> server name (ie. CIGNT3 => CIGMAIL) without having to touch each machine.  I
>>> wrote a VBS script that work GREAT on 2000 machines, but it generates the
>>> error:

>>> "Microsoft VBScript runtime error: File name or class name not found during
>>> Automation operation: 'getobject'"

>>> when I try to run it with CSCRIPT on 98 machines (even thought the 98 machine
>>> reports that the CSCRIPT version is 5.6).

>>> Obviously it's the Set objRegistry =
>>> getobject("winmgmts:root\default:stdregprov") line.  I guess I don't
>>understand
>>> the differences between pure WSH and VBS.  Any help?

>>> NOTE: code best viewed with non-proportional/fixed pitch font
>>> '******************************* Code follows *************************

>>> option explicit

>>> Const HKEY_CLASSES_ROOT = &H80000000
>>> Const HKEY_CURRENT_USER = &H80000001
>>> Const HKEY_LOCAL_MACHINE = &H80000002
>>> Const HKEY_USERS = &H80000003

>>> Dim objRegistry
>>> dim intTotalMatch

>>>     intTotalMatch = 0

>>>     Set objRegistry = getobject("winmgmts:root\default:stdregprov")

>>>     wscript.echo "Searching ... HKEY_USERS"
>>>     call SearchReplace(HKEY_USERS, _
>>>                        "", _
>>>                        objRegistry, _
>>>                        "COLNTSRV3", _
>>>                        "CIGMAIL", _
>>>                        intTotalMatch)

>>>     wscript.echo "Searching ... HKEY_CURRENT_USER"
>>>     call SearchReplace(HKEY_CURRENT_USER, _
>>>                        "Software\Microsoft\Windows NT\CurrentVersion\Windows
>>> Messaging Subsystem\Profiles\MS Exchange Settings", _
>>>                        objRegistry, _
>>>                        "COLNTSRV3", _
>>>                        "CIGMAIL", _
>>>                        intTotalMatch)

>>>     Set objRegistry = Nothing

>>>     if intTotalMatch = 0 then
>>>         wscript.echo "TotalMatches: None Found"
>>>     else
>>>         wscript.echo "TotalMatches: " & inttotalmatch
>>>     end if

>>> wscript.quit

>>> '*************************************************************************
>>> ' Search and Replace
>>> '*************************************************************************
>>> function SearchReplace(lngHive, _
>>>                        strKey, _
>>>                        objRegistry, _
>>>                        strSearch, _
>>>                        strReplace, _
>>>                        intMatchCount)

>>> const REG_SZ        = 1
>>> const REG_EXPAND_SZ = 2
>>> const REG_BINARY    = 3
>>> const REG_DWORD     = 4
>>> const REG_MULTI_SZ  = 7

>>> Dim strSubKey
>>> dim strValue
>>> dim strFullKey
>>> dim strName
>>> dim strMultiStrings
>>> dim strThisValue
>>> dim arrNames
>>> dim arrTypes
>>> dim arrTypeNames
>>> Dim arrSubKeys
>>> dim arrBinary
>>> dim intX
>>> dim intIndex
>>> dim lngReturn
>>> dim lngDWORD

>>>     arrTypeNames = array("","REG_SZ","REG_EXPAND_SZ","REG_BINARY", _
>>>                          "REG_DWORD","","","REG_MULTI_SZ")

>>>     If objRegistry.EnumKey(lngHive, strKey, arrSubKeys) = 0 Then

>>>         For Each strSubKey In arrSubKeys

>>>             strFullKey = BackSlash(strKey, TRUE) & strSubKey

>>>             call SearchReplace(lngHive, _
>>>                                strFullKey, _
>>>                                objRegistry, _
>>>                                strSearch, _
>>>                                strReplace, _
>>>                                intMatchCount)

>>>             'at this point we're at the top, we need to
>>>             'get a list of the values

>>>             lngReturn = objRegistry.EnumValues(lngHive, _
>>>                                                strFullKey, _
>>>                                                arrNames, _
>>>                                                arrTypes)

>>>             If (lngReturn = 0) And (Err.Number = 0) Then

>>>                 For intIndex = 0 To UBound(arrNames)

>>>                     'we're only checking the REG_SZ values
>>>                     Select Case arrTypes(intIndex)

>>>                         Case REG_SZ

>>>                             lngReturn = objRegistry.GetStringValue(lngHive, _
>>>                                                                  strFullKey, _

>>> arrNames(intIndex),_
>>>                                                                  strValue)
>>> 'the default named value
>>>                             If arrNames(intIndex) = "" Then
>>>                                 arrNames(intIndex) =  "default"
>>>                             End If

>>>                     End Select

>>>                     if ucase(strValue) = ucase(strSearch) then

>>> '** NOTE: I'll impletment a write, when everything
>>> 'else is working.
>>>                          'call wshShell.RegWrite(strFullKey, _
>>>                                                  strReplace, _
>>> arrTypes(intIndex))
>>>                          intMatchCount = cint(intMatchCount) + 1

>>>                     end if

>>>                 Next

>>>              end if

>>>         Next

>>>     End If

>>> End function

>>> '*************************************************************************
>>> ' Make sure a backslash exists, if wanted
>>> '*************************************************************************
>>> function BackSlash(strTemp, blnForceBS)

>>>     if len(strTemp) > 0 then
>>>         if blnForceBS then
>>>             if right(strTemp,1) <> "\" then 'add it
>>>                 strTemp = strTemp & "\"
>>>             end if
>>>         else
>>>             if right(strTemp,1) = "\" then 'get rid of it
>>>                 strTemp = left(strtemp,len(strtemp) - 1)
>>>             end if
>>>         end if
>>>     end if

>>>     BackSlash = strTemp

>>> end function



Sun, 21 Nov 2004 23:56:30 GMT  
 Registry - search & replace
Yes!

That part is easy:

Function IsNt()
    Dim env
    set env = CreateObject("Wscript.Shell").Environment
    IsNt =CStr(CBool(Env("OS") = "Windows_NT"))
End Function 'IsNt

Note that this returns true on all NT/2000/XP systems.

The larger overall problem *might* have a solution by scripting Regedit if
everything is in a fairly small are of the registry; I have a global RegEdit
export I've played with, but it is not nearly robust enough to avoid giving you
other headaches at present.


Quote:
> After some research I realized the problem with WMI myself.  And you've hit
the
> nail on the head - if I touch each machine to install WMI then I might as well
> fix the server issue.

> the problem is NO, the keys aren't necessarily the same for all machines.  The
> code I included works GREAT on 2000 machines, so I think that my solution.
For
> the 98 machines I'll recompare the keys, there are only 2 or 3 (out of 21)
that
> differ machine to machine.  I'll try changing the common keys and see (pray)
> that the unique keys will be cascadedly updated by Outlook when it runs.

> BTW:  Is there a pure WSH method for determining OS.  (ie. WSCRIPT.ENVIRONMENT
> ???)


> >>The problem you have is that WMI is not installed on the Win9x machines.
You
> >>*could* install it on them, but that means touching all of them anyway.

> >>Are the affected values in the same location in the registry from machine to
> >>machine on Win9x? A simple RegWrite could solve your problem if so.



> >>> I'm trying to replace all occurances of my Exchange server with an updated
> >>> server name (ie. CIGNT3 => CIGMAIL) without having to touch each machine.
I
> >>> wrote a VBS script that work GREAT on 2000 machines, but it generates the
> >>> error:

> >>> "Microsoft VBScript runtime error: File name or class name not found
during
> >>> Automation operation: 'getobject'"

> >>> when I try to run it with CSCRIPT on 98 machines (even thought the 98
machine
> >>> reports that the CSCRIPT version is 5.6).

> >>> Obviously it's the Set objRegistry =
> >>> getobject("winmgmts:root\default:stdregprov") line.  I guess I don't
> >>understand
> >>> the differences between pure WSH and VBS.  Any help?

> >>> NOTE: code best viewed with non-proportional/fixed pitch font
> >>> '******************************* Code follows *************************

> >>> option explicit

> >>> Const HKEY_CLASSES_ROOT = &H80000000
> >>> Const HKEY_CURRENT_USER = &H80000001
> >>> Const HKEY_LOCAL_MACHINE = &H80000002
> >>> Const HKEY_USERS = &H80000003

> >>> Dim objRegistry
> >>> dim intTotalMatch

> >>>     intTotalMatch = 0

> >>>     Set objRegistry = getobject("winmgmts:root\default:stdregprov")

> >>>     wscript.echo "Searching ... HKEY_USERS"
> >>>     call SearchReplace(HKEY_USERS, _
> >>>                        "", _
> >>>                        objRegistry, _
> >>>                        "COLNTSRV3", _
> >>>                        "CIGMAIL", _
> >>>                        intTotalMatch)

> >>>     wscript.echo "Searching ... HKEY_CURRENT_USER"
> >>>     call SearchReplace(HKEY_CURRENT_USER, _
> >>>                        "Software\Microsoft\Windows

NT\CurrentVersion\Windows

- Show quoted text -

Quote:
> >>> Messaging Subsystem\Profiles\MS Exchange Settings", _
> >>>                        objRegistry, _
> >>>                        "COLNTSRV3", _
> >>>                        "CIGMAIL", _
> >>>                        intTotalMatch)

> >>>     Set objRegistry = Nothing

> >>>     if intTotalMatch = 0 then
> >>>         wscript.echo "TotalMatches: None Found"
> >>>     else
> >>>         wscript.echo "TotalMatches: " & inttotalmatch
> >>>     end if

> >>> wscript.quit

> >>> '*************************************************************************
> >>> ' Search and Replace
> >>> '*************************************************************************
> >>> function SearchReplace(lngHive, _
> >>>                        strKey, _
> >>>                        objRegistry, _
> >>>                        strSearch, _
> >>>                        strReplace, _
> >>>                        intMatchCount)

> >>> const REG_SZ        = 1
> >>> const REG_EXPAND_SZ = 2
> >>> const REG_BINARY    = 3
> >>> const REG_DWORD     = 4
> >>> const REG_MULTI_SZ  = 7

> >>> Dim strSubKey
> >>> dim strValue
> >>> dim strFullKey
> >>> dim strName
> >>> dim strMultiStrings
> >>> dim strThisValue
> >>> dim arrNames
> >>> dim arrTypes
> >>> dim arrTypeNames
> >>> Dim arrSubKeys
> >>> dim arrBinary
> >>> dim intX
> >>> dim intIndex
> >>> dim lngReturn
> >>> dim lngDWORD

> >>>     arrTypeNames = array("","REG_SZ","REG_EXPAND_SZ","REG_BINARY", _
> >>>                          "REG_DWORD","","","REG_MULTI_SZ")

> >>>     If objRegistry.EnumKey(lngHive, strKey, arrSubKeys) = 0 Then

> >>>         For Each strSubKey In arrSubKeys

> >>>             strFullKey = BackSlash(strKey, TRUE) & strSubKey

> >>>             call SearchReplace(lngHive, _
> >>>                                strFullKey, _
> >>>                                objRegistry, _
> >>>                                strSearch, _
> >>>                                strReplace, _
> >>>                                intMatchCount)

> >>>             'at this point we're at the top, we need to
> >>>             'get a list of the values

> >>>             lngReturn = objRegistry.EnumValues(lngHive, _
> >>>                                                strFullKey, _
> >>>                                                arrNames, _
> >>>                                                arrTypes)

> >>>             If (lngReturn = 0) And (Err.Number = 0) Then

> >>>                 For intIndex = 0 To UBound(arrNames)

> >>>                     'we're only checking the REG_SZ values
> >>>                     Select Case arrTypes(intIndex)

> >>>                         Case REG_SZ

> >>>                             lngReturn =

objRegistry.GetStringValue(lngHive, _

- Show quoted text -

Quote:

strFullKey, _

> >>> arrNames(intIndex),_
> >>>                                                                  strValue)
> >>> 'the default named value
> >>>                             If arrNames(intIndex) = "" Then
> >>>                                 arrNames(intIndex) =  "default"
> >>>                             End If

> >>>                     End Select

> >>>                     if ucase(strValue) = ucase(strSearch) then

> >>> '** NOTE: I'll impletment a write, when everything
> >>> 'else is working.
> >>>                          'call wshShell.RegWrite(strFullKey, _
> >>>                                                  strReplace, _
> >>> arrTypes(intIndex))
> >>>                          intMatchCount = cint(intMatchCount) + 1

> >>>                     end if

> >>>                 Next

> >>>              end if

> >>>         Next

> >>>     End If

> >>> End function

> >>> '*************************************************************************
> >>> ' Make sure a backslash exists, if wanted
> >>> '*************************************************************************
> >>> function BackSlash(strTemp, blnForceBS)

> >>>     if len(strTemp) > 0 then
> >>>         if blnForceBS then
> >>>             if right(strTemp,1) <> "\" then 'add it
> >>>                 strTemp = strTemp & "\"
> >>>             end if
> >>>         else
> >>>             if right(strTemp,1) = "\" then 'get rid of it
> >>>                 strTemp = left(strtemp,len(strtemp) - 1)
> >>>             end if
> >>>         end if
> >>>     end if

> >>>     BackSlash = strTemp

> >>> end function



Mon, 22 Nov 2004 04:37:41 GMT  
 Registry - search & replace
Alex,

Thanks,  that worked great (and saved me some research). I've only been playing
w/ VBS/WSH/WMI for 3 days now, that's why I get kind of confused when it comes
to where WSH quits and WMI begins.  I have a strong VB background so the VBS
comes naturally.  Well, I'll keep plugging away.  You'd think there would be a
freeware util that would allow you to do a simple registry search & replace w/o
requiring additional libraries (DLL) or components installed.  Thanks again for
your help,  I'm sure you'll see me here again.

BTW: Great last name - with a name like Schamberger I can appreciate a surname
with a few extra syllables in it.


Quote:
>>Function IsNt()
>>    Dim env
>>    set env = CreateObject("Wscript.Shell").Environment
>>    IsNt =CStr(CBool(Env("OS") = "Windows_NT"))
>>End Function 'IsNt



Mon, 22 Nov 2004 05:50:40 GMT  
 Registry - search & replace
Yeah, taught me to spell early. :)

There is no control I have found which does this, although I haven't looked hard
recently.

My "technique", which isn't quite ready for bigtime yet, is to export a registry
subkey using Regedit, like this;

regedit /s /e HKEY_CURRENT_USER\Somepath regfile.reg.

It is then possible to do a global search and replace on the regfile, but it is
also dangerous - so a fairly certain way of checking the modified file (and
t{*filter*} down the size of the import) needs to be done.

If the data is kept in a specific named subkey (or one of some) you could just
attempt regreads with error control on each key; if the value is under a key
with a unique GUID name, though, that won't work very well.


Quote:
> Alex,

> Thanks,  that worked great (and saved me some research). I've only been
playing
> w/ VBS/WSH/WMI for 3 days now, that's why I get kind of confused when it comes
> to where WSH quits and WMI begins.  I have a strong VB background so the VBS
> comes naturally.  Well, I'll keep plugging away.  You'd think there would be a
> freeware util that would allow you to do a simple registry search & replace
w/o
> requiring additional libraries (DLL) or components installed.  Thanks again
for
> your help,  I'm sure you'll see me here again.

> BTW: Great last name - with a name like Schamberger I can appreciate a surname
> with a few extra syllables in it.


> >>Function IsNt()
> >>    Dim env
> >>    set env = CreateObject("Wscript.Shell").Environment
> >>    IsNt =CStr(CBool(Env("OS") = "Windows_NT"))
> >>End Function 'IsNt



Mon, 22 Nov 2004 06:56:39 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. registry - search & replace

2. NEED HELP - Search and replace registry script

3. VBS search and replace in registry

4. searching for registry entries and replacing them

5. Registry Search and Replace

6. NEED HELP - Search and replace registry script

7. Registry Search and Replace???

8. Registry Search and Replace???

9. Search & Replace

10. Search & Replace in Word 2000

11. Search & Replace

12. Search, Replace & Save

 

 
Powered by phpBB® Forum Software