problem with the method GetSubKeyNames()

Posted by Tobi under C# on 8/5/2013 | Points: 10 | Views : 1143 | Status : [Member] | Replies : 2
hi everybody,

i want to write a windows service to list the trusted websites in my computer
for this, i have to open the key at the right path and then list the subkeys.

here is my code but it gives me an exception:

 protected override void OnStart(string[] args)
{

RegistryKey localKey;

if (Environment.Is64BitOperatingSystem)
{
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry64);
}
else
{
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry32);
}

try
{



RegistryKey mycle = localKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains");




string[] souscle = mycle.GetSubKeyNames();

foreach (string subKeyName in souscle)
{
TextWriter file = new StreamWriter(@"C:\Temp\journal.txt", true);
file.WriteLine("je suis la2" + "\n");
file.WriteLine(subKeyName.ToString() + "\n");
}


}
catch (Exception e)
{
TextWriter file = new StreamWriter(@"C:\Temp\journal.txt", true);
file.WriteLine(e.ToString() + "\n");
file.Close();
}
}


please help i m trying to resolve this problem for lot of days but i can t
thanks




Responses

Posted by: Tobi on: 8/7/2013 [Member] Starter | Points: 25

Up
0
Down
please if someone could help me it will be very cool because i m a beginner in this domain
i just want to list the trusted website in the computer
the path in the registry is:
CurrentUser\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
then every subkey represents a trusted website
i would like to list all the subkeys
the problem is that my code is simple but doesn t work and i dont understand why
here is my code:

protected override void OnStart(string[] args)

{


TextWriter file = new StreamWriter(@"C:\Temp\journal.txt", true);
file.WriteLine("ecriture okkk" + "\n");
file.Close();

Thread thr = new Thread(new ThreadStart(run));
}

static void run()
{
RegistryKey localKey;
TextWriter file = new StreamWriter(@"C:\Temp\journal.txt", true);
file.WriteLine("je suis la" + "\n");

if (Environment.Is64BitOperatingSystem)
{
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry64);
}
else
{
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry32);
}

try
{



RegistryKey mycle = localKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains", false);


file.WriteLine("je suis la" + "\n");

string[] souscle = mycle.GetSubKeyNames();

foreach (string subKeyName in souscle)
{

file.WriteLine("je suis la" + "\n");
file.WriteLine(subKeyName + "\n");

}
file.Close();


}
catch (Exception e)
{

file.WriteLine(e.ToString() + "\n");
file.Close();
}


}


Tobi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 8/7/2013 [Member] Starter | Points: 25

Up
0
Down
Try other way-
Maybe below links would help:
http://blogs.technet.com/b/heyscriptingguy/archive/2005/02/14/how-can-i-add-a-web-site-to-the-trusted-sites-zone.aspx

OR TRY

http://stackoverflow.com/questions/972345/programmatically-add-trusted-sites-to-internet-explorer

Hey u will find some more links in Google! Don't lose Hope \m/
I GOOGLED 'list websites as trusted from code'

http://hashtagakash.wordpress.com/

Tobi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response