4 Ekim 2015 Pazar

Windows Registry

Windows Registry Nedir?
Ağaç şeklinde bir veritabanıdır. Kullanıması artık pek tavsiye edilmiyor. Bazı sebepler şöyle.
  • The registry is a single point of failure. That's why every single registry editing tip you'll ever find starts with a big fat screaming disclaimer about how you can break your computer with regedit.
  • The registry is opaque and binary. As much as I dislike the angle bracket tax, at least XML config files are reasonably human-readable, and they allow as many comments as you see fit.
  • The registry has to be in sync with the filesystem. Delete an application without "uninstalling" it and you're left with stale registry cruft. Or if an app has a poorly written uninstaller. The filesystem is no longer the statement of record-- it has to be kept in sync with the registry somehow. It's a total violation of the DRY principle.
  • The registry is monolithic. Let's say you wanted to move an application to a different path on your machine, or even to a different machine altogether. Good luck extracting the relevant settings for that one particular application from the giant registry tarball. A given application typically has dozens of settings strewn all over the registry.

Hive Nedir?
Windows Registry konu başlıklarına bölünmüş. Başlıklara da Hive (kovan) ismi verilmiş.


Temel hive'lar şunlar.
HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, HKEY_USERS

HKEY_CURRENT_USER
Giriş yapmış kullanıcı hakkında bilgi saklayan kovan.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
sadece bir kere çalışmasını istediğimiz iş için kullanılır.

HKEY_USERS
Kullanıcılar hakkında bilgi saklayan kovan.

Registry Sınıfı
LocalMachine View
Şöyle kullanırız.
Registry.LocalMachine;

DeleteSubKey metodu
Örnek
var hklm = Microsoft.Win32.Registry.LocalMachine;
var subkey = hklm.OpenSubKey("Software\\Wow6432Node\\WindowsApplication1", true);
subkey.DeleteSubKey("Status");
DeleteSubKeyTree metodu
Örnek:
Registry.CurrentUser.DeleteSubKeyTree("Test9999");
DeleteValue metodu
Örnek
string keyName = @"Software\Microsoft\Windows\CurrentVersion\Run";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
{
  key.DeleteValue("MyApp");
}
RegistryKey Sınıfı
OpenBaseKey metodu
Bir key şöyle açılır.
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)




Hiç yorum yok:

Yorum Gönder