mardi 23 décembre 2014

How to check a key value in a if statment [on hold]

I'm trying to have a if statement look at the key vale and determine if it is IE.HTTP or not and if not to run the code that changes it to IE.HTTP


Im not quite sure on how to get it to read the key value, any sort of help would be much appreciated



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
using System.Windows.Forms; //Added in R-Click "ConsoleApplication2" > Add > Reference > System.Windows.Forms


namespace ChangeDefaultBrowser
{

class Program
{
static void Main()
{
string input;

using( RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\")) //Locates the registry value
if (myKey != null)
{
string val = myKey.GetValue("Progid");
if (myKey == null)
{
Console.WriteLine("Not found");
}
else
{
Console.WriteLine("found key");
}


Console.WriteLine("The default browser is already set to Internet Explorer.");
return;
}
else
{
try
{

myKey.SetValue("Progid", "IE.HTTP", RegistryValueKind.String); //Sets the 'Progid' value to IE as default browser (IE.HTTP) using String date type
Console.WriteLine("The registry key has been changed.", "Title Goes Here"); //Error Checking
Console.WriteLine("Press Return to Exit"); //Error Checking
input = Console.ReadLine(); //Error Checking
return;

}
catch
{
Console.WriteLine("There was an error changing the registry key", "Title goes here"); //Error Checking
Console.WriteLine("Press Return to Exit"); //Error Checking
input = Console.ReadLine(); //Error Checking
return;
}
}
}
}
}

Aucun commentaire:

Enregistrer un commentaire