How to validate an empty array when reading Subkey names...
what trying accomplish make sure name "enabled" exists or not exist under hkcu\\software\\microsoft\\internet explorer\\tabbedbrowsing. but, stuck in reading it.
the following if (names3a != null) true never goes because there no names under " foreach (string name in names3a)" stuck in part.
thanks for help
code:
//tabs/disable tabbed browsing
console.writeline("");
registrykey subkey3 = key.opensubkey("software\\microsoft\\internet explorer", true);
registrykey subkey3a = key.opensubkey("software\\microsoft\\internet explorer\\tabbedbrowsing", true);
string[] names3 = subkey3.getsubkeynames();
string yesenablednameexists = "";
string noenablednameexists = "";
if (subkey3a == null)
{
// no found tabbedbrowsing
console.writeline("wow, empty");
system.threading.thread.sleep(5000);
console.writeline("no found tabbedbrowsing, creating ");
console.writeline("setting right ge recommendation");
subkey3.createsubkey("tabbedbrowsing");
registrykey subkey3aa = key.opensubkey("software\\microsoft\\internet explorer\\tabbedbrowsing", true);
subkey3aa.setvalue("enabled", "0", registryvaluekind.dword);
}
else
{
string[] names3a = subkey3a.getvaluenames();
if (names3a != null)
{
foreach (string name in names3a)
{
if (name.equals("enabled", stringcomparison.currentculture))
{
// found tabbedbrowsing enabled
yesenablednameexists = "1";
break;
}
else
{
// no found tabbedbrowsing enabled
noenablednameexists = "1";
}
}
if (names3a[0].equals("string[0]", stringcomparison.currentculture))
{
console.writeline("no found enabled, creating ");
console.writeline("setting right ge recommendation");
subkey3a.setvalue("enabled", "0", registryvaluekind.dword);
}
if (yesenablednameexists == "1")
{
console.writeline("found tabbedbrowsing , enabled");
int myvalue3a = (int)subkey3a.getvalue("enabled");
if (myvalue3a == 0)
{
console.writeline("recommended tabbed browsing value: {0} unchecked tabbed browsing", myvalue3a);
}
else
{
console.writeline("setting right ge recommendation");
subkey3a.setvalue("enabled", "0", registryvaluekind.dword);
}
}
if (noenablednameexists == "1")
{
console.writeline("no found enabled, creating ");
console.writeline("setting right ge recommendation");
subkey3a.setvalue("enabled", "0", registryvaluekind.dword);
}
}
else
{
console.writeline("no found enabled, creating ");
console.writeline("setting right ge recommendation");
subkey3a.setvalue("enabled", "0", registryvaluekind.dword);
}
}
hannes
if have got questions this, ask.
in perfect world,
users never enter data in wrong form,
files choose open exist
, code never have bugs.
c# vb.net: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment