After testing on Oracle10g, other clients should be similar. Code
Registrykey HKLM = Registry. localmachine;
Registrykey hksoftware = HKLM. opensubkey ( " Software " );
Registrykey hkoracle = Hksoftware. opensubkey ( " Oracle " );
If (Hkoracle = Null )
{
MessageBox. Show ( " The installation path of the Oracle client is not found. " );
Return ;
}
String Oraclient = Null ;
Foreach ( String TMP In Hkoracle. getsubkeynames ())
{
If (TMP. Contains ( " Key_clientlient " ))
{
Oraclient = TMP;
Break ;
}
}
If (Clientlient = Null )
{
MessageBox. Show ( " The installation path of the Oracle client is not found. " );
Return ;
}
String path = ( String ) Hkoracle. opensubkey (publish lient). getvalue ( " ORACLE_HOME " );
String TNS = File. readalltext (path. Combine (path, @" Network \ admin \ tnsnames. ora " ));
If ( ! RegEx. ismatch (TNS, @" (? S) km \ s * = \ s * \ (. + \) " ))
TNS + = @"
Km =
(Description =
(Address = (Protocol = TCP) (host = 10.0.192.23) (Port = 1521 ))
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = km)
)
)
" ;
File. writealltext (path. Combine (path, @" Network \ admin \ tnsnames. ora " ), TNS );