viernes, octubre 05, 2007

Registry Key

Es posible que una de las tareas que sea necesario realizar cuando se instala una aplicación es la de crear claves en el registro, para establecer ciertas caracteristicas de nuestra aplicación, aquí les dejo un fragmento de código que justamente crea una clave de registro si al comprobarla éta no existe.

private static void TestRegistryKey()
{
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
if (ad.IsFirstRun)
{
string keyPath = @"SOFTWARE\RegistryKeypProject\RegistryKey";
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(keyPath, true);
if (registryKey != null)
{
if (registryKey.GetValue("RunOnce") != null)
{
string runOnce = registryKey.GetValue("RunOnce").ToString();
if (runOnce == "0")
{
// your code
}
}
else
{
registryKey.SetValue("RunOnce", "0");
// your code
registryKey.SetValue("RunOnce", "1");
}
}
}
}

No hay comentarios.: