mistabroadway Posted December 6, 2011 Share Posted December 6, 2011 Hey guys, I'm looking to do a registry search for all ODBC connections that are connecting to a specific server that is about to be retired. I then want to point those connections to the new server. The problem I seem to be running into is the Key may be different depending on the computer. The String I want to change should be somewhere in this area but the exact key is unknown. \\HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\[RandomKey]\ They old string is Server, REG_SZ, FTWSQL03\MSSQL3 The new string would need to be changed to FTWMSQLP19\MSSQLP19 I'm not really sure how registry search works even though I've seen a few threads referencing it. ;Search to see if the following key exists inside of an unknown key $OldString = "Server" , "REG_SZ" , "FTWSQL03\MSSQL3") $NewString = "Server" , "REG_SZ" , "FTWMSQLP19\MSSQLP19") $Key1 = RegRead("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\[Unknown Key 1]", & $OldString $Key2 = RegRead("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\[Unknown Key 2]", & $OldString ;$Key3... ;$Key4... If $Key1 = 1 Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\[Unknown Key 1]", $NewString Else $Key2 = 1 Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\[Unknown Key 2]", $NewString Else EndIf I'm sure I'm way off on where I'm going with this since most of this is new to me. My thought was to search all the sub-keys within HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI for a string that is Server=FTWSQL03\MSSQL3 then change it to Server=FTWMSQLP19\MSSQLP19 Link to comment Share on other sites More sharing options...
water Posted December 6, 2011 Share Posted December 6, 2011 There was a similar question two days ago and I suggested to have a look at a made for searching the registry.Maybe this helps. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ripdad Posted December 6, 2011 Share Posted December 6, 2011 perhaps something like this ... Local $sKey, $sVal Local $OldString = 'FTWSQL03MSSQL3' Local $NewString = 'FTWMSQLP19MSSQLP19' Local $HKCU_ODBC = 'HKEY_CURRENT_USERSOFTWAREODBCODBC.INI' For $i = 1 To 50 $sKey = RegEnumKey($HKCU_ODBC, $i) If @error <> 0 Then ExitLoop $sVal = RegRead($HKCU_ODBC & '' & $sKey, 'Server') If @error <> 0 Then ContinueLoop MsgBox(0, '', 'Key: ' & $sKey & @CRLF & 'Value: ' & $sVal); <-- debug (have a peek) If $sVal = $OldString Then RegWrite($HKCU_ODBC & '' & $sKey, 'Server', 'REG_SZ', $NewString) EndIf NextBy the way, you can't do this in AutoIt ...$OldString = "Server" , "REG_SZ" , "FTWSQL03MSSQL3")Commas and brackets for a function, must reside within the function. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
mistabroadway Posted December 7, 2011 Author Share Posted December 7, 2011 Thanks ripdad! That's exactly what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now