The name does not exist in the current context, simple code..

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello all,
I am a newbie with C# and trying to learn this language but i get the following error:
"The name "YesSyncMode5NameExists" does not exist in the current context. Thanks for your help.

Here is the code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace UPI_IE8_GE_Settings
{
class Program
{
static void Main(string[] args)
{
//placeholder for the result
object result = null;

//Select the RegistryHive you wish to read from
RegistryKey key0 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "");

//Select the path within the hive
RegistryKey subkey = key0.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion");

//If the subkey is null, it means that the path within the hive doesnt exist
if (subkey != null)
{
//Read the key
result = subkey.GetValue("ProductName");
}

if(result != null)
{
//The GetValue-method only returns object as this can be string, int, binary,... so keep in mind you need to cast it!
Console.WriteLine((string)result);
}
else
{
Console.WriteLine("There was no result.");
}

//**************************BEGIN GENERAL TAB***********************************
//BROWSING HISTORY/CHECK FOR NEWER VERSIONS OF STORED PAGES

//Select the RegistryHive you wish to read from
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, "");

//Select the path within the hive
RegistryKey subkey1 = key.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings",true);
string[] names = subkey1.GetValueNames();
//string YesSyncMode5NameExists,NoSyncMode5NameExists;

foreach (string name in names)
{
if (name.Equals("SyncMode5", StringComparison.CurrentCulture))
{
// Found SyncMode5
Console.WriteLine("found SyncMode5");
string YesSyncMode5NameExists = "1";
string NoSyncMode5NameExists = "99";
break;
}
else
{
//Console.WriteLine("found SyncMode5 but different or NOT found SyncMode5");
// No Found SyncMode5
string NoSyncMode5NameExists = "1";
subkey1.SetValue("SyncMode5", "2", RegistryValueKind.DWord);
break;
}
}
//bool OneZero = YesSyncMode5NameExists.Equals("1", StringComparison.Ordinal);
//int OneZero = String.Compare(YesSyncMode5NameExists,"1",StringComparison.CurrentCulture);
if (YesSyncMode5NameExists = "1" )
{Console.WriteLine(""); }
//{ Console.WriteLine("Found SyncMode5 ans the string comparison is True"); }




}
}
}

Thanks for your help,

View the full article
 
Back
Top