method one:
// read the registry, obtain the installation path of sqlserver RegistryKey pRegKey = Registry.LocalMachine; pRegKey = pRegKey.OpenSubKey ( "SOFTWARE // Microsoft // MSSQLServer // Setup"); Object SqlPath = pRegKey.GetValue ( "SQLDataRoot") ;