954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with another key. (Almost done)!

I've finally gotten this thing to open information and place it into a text file.
My next question is, how do I get this part to work? I've bolded the registry key that I'm trying to put into the notepad file, but this one just will not work. What am I doing wrong?

using System;
using System.IO;
using Microsoft.Win32;
using System.Text;
using System.Diagnostics;	
using System.Data;
using System.Collections.Generic;
using System.ComponentModel;

class Test 
{
    public static void Main() 
    {
        // Create an instance of StreamWriter to write text to a file.
        // The using statement also closes the StreamWriter.
        using (StreamWriter sw = new StreamWriter("SysInfo.txt")) 
{
            RegistryKey hklm = Registry.LocalMachine;
            hklm = hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            Object obp = hklm.GetValue("Identifier");
            sw.WriteLine("Processor Identifier: " + obp);

         <strong>RegistryKey hklp = Registry.HKEY_CURRENT_USER;
            hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\Software\America Online\AOL Instant Messenger (TM)\CurrentVersion\Users");
            Object obc = hklp.GetValue("Users");
            sw.WriteLine("Users: {0} ", obc);</strong>

            RegistryKey biosv = Registry.LocalMachine;
            biosv = biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapter\\4");
            Object obv = biosv.GetValue("Identifier");
            sw.WriteLine("Bios Status: {0} ", obv);

            RegistryKey biosd = Registry.LocalMachine;
            biosd = biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
            Object obd = biosd.GetValue("SystemBiosDate");
            sw.WriteLine("Bios Date: {0} ", obd);

            RegistryKey bios = Registry.LocalMachine;
            bios = bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
            Object obs = bios.GetValue("Identifier");
            sw.WriteLine("System Identifer: {0} ", obs);
            sw.Close();

        }
    }
}


Basically I want it to place all those users on my computer into the file.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Whats the problem? you didnt say if there was an error.

What is the value in the registry? Is it a delimited text?

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

I think I'm using the wrong information to grab the key from the registry.
All it does it underline this part: HKEY_CURRENT_USER\Software\America Online\AOL Instant Messenger (TM)\CurrentVersion\Users in red and gives me this message: "Unrecognized escape sequence."

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Thats because you made a mistake. In C# a \ is an escape sequence (used for special characters such as carriage return \r or new line \n). So a \ in a string is also a special character and so needs the escape sequence ie \\. As you see in your other reg strings (you left it out in this one).
The other way round it if you are not using special characters in your string is to use the @ symbol in front of the quotes which tells c# to take the string literally (beware if you use this then \r will appear as \r not a carriage return.

So your choices are
hklp = hklp.OpenSubKey(@"HKEY_CURRENT_USER\Software\America Online\AOL Instant Messenger (TM)\CurrentVersion\Users");

or hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");

both will work :)

hope it helps

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Alright then. So now I have changed that part to

RegistryKey hklp = Registry.CurrentUser;
            hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");
try
{
	Object obc = hklp.GetValue("Identifier");
	sw.WriteLine("Users: {0} " + obc.ToString());
}
catch (Exception exc)
{
	sw.WriteLine(exc.Message);
}


Now when the program runs, it creates the file and everything, but in the part where it's supposed to have the AIM sign ons, it says "Object reference not set to an instance of an object."

Blah...this is frustrating. And I know I'm using the correct registry key path.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

but you went and changed the key now.
it used to be
Object obc = hklp.GetValue("Users");
and now you just posted
Object obc = hklp.GetValue("Identifier");

be careful when you code you make mistakes if not paying attention. If it is frustrating then walk away for 30 minutes - you will come back refreshed.

Anyway, put the proper key in from your registry and it will work

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Done, but it's still not working.
Apparently there's no way to get it to do that.
Oh well.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

if you can see it in reg edit then it can be done in C#.
The trouble is i am working blind here as cannot see your registry etc and dont have AIM myself.
Can you tell me what the value is in your registry that you are trying to display? I dont need the names of your contacts, just whether it is a dword and a sample of the content (eg comma delimited string, or semi colon or what. Then i can help more

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

I made a screenshot for you...hopefully that will help you to see what I'm talking about.

I outlined the information I want in pink.

[img]http://www.classic-chick.net/registry.jpg[/img]

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

ok that helps a lot :)

you need this bit of code

RegistryKey hklp = Registry.CurrentUser;
            hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");
try
{
string[] valnames = hklp.GetValueNames();
for (int i = 0; i < valnames.count; i++)
     {
	Object obc = hklp.GetValue(valnames[i]);
	sw.WriteLine("Users: {0} " + obc.ToString());
     }
}
catch (Exception exc)
{
	sw.WriteLine(exc.Message);
}


See if that helps

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 
for (int i = 0; i < valnames.count; i++)


'System.Array' does not contain a definition for 'count'

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

sorry my fault not paying attention..
valnames.length

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Well it says the same thing now, only with 'length' rather than 'count.'
:/

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

c# is case sensitive... i thought you wouldnt just blindly copy n paste.
valnames.Length

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Yeahh... sorry, I should have noticed that myself.
I've been working on this too much today. Sorry.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

lol dont worry.. will teach us both to pay more attention.
Like i said before... take a break and come back to it.. sometimes you cant see the wood for the trees or just keep following the wrong path over and over.

It should work now. The GetValueNames() should return a string array with all the names in the key (not the data you highlighted in pink but the corresponding Name column) then we went through each of those in turn and called the GetValue passing in the name one at a time... this will then return your highlighted data one at a time.
Follow it?

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

The same thing is still happening. (The object reference not set to an instance of an object).

Here's the entire program once again:

using System;
using System.IO;
using Microsoft.Win32;
using System.Text;
using System.Diagnostics;	
using System.Data;
using System.Collections.Generic;
using System.ComponentModel;

class Test 
{
    public static void Main() 
    {
        // Create an instance of StreamWriter to write text to a file.
        // The using statement also closes the StreamWriter.
        using (StreamWriter sw = new StreamWriter("SysInfo.txt")) 
{
            RegistryKey hklm = Registry.LocalMachine;
            hklm = hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            Object obp = hklm.GetValue("Identifier");
            sw.WriteLine("Processor Identifier: " + obp);

            RegistryKey hklp = Registry.CurrentUser;
            hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");
try
{
string[] valnames = hklp.GetValueNames();
for (int i = 0; i < valnames.Length; i++)
     {
	Object obc = hklp.GetValue(valnames[i]);
	sw.WriteLine("Users: {0} " + obc.ToString());
     }
}
catch (Exception exc)
{
	sw.WriteLine(exc.Message);
}
            RegistryKey biosv = Registry.LocalMachine;
            biosv = biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapter\\4");
            Object obv = biosv.GetValue("Identifier");
            sw.WriteLine("Bios Status: {0} ", obv);

            RegistryKey biosd = Registry.LocalMachine;
            biosd = biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
            Object obd = biosd.GetValue("SystemBiosDate");
            sw.WriteLine("Bios Date: {0} ", obd);

            RegistryKey bios = Registry.LocalMachine;
            bios = bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
            Object obs = bios.GetValue("Identifier");
            sw.WriteLine("System Identifer: {0} ", obs);
            sw.Close();

        }
    }
}

I'm not seeing anything wrong here. This is becoming impossible. If I can't get it to work after a few more tries, I guess I'll just give up. Haha.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

not paying attention again!!! lol
hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");

is wrong. hklp already equals HKEY_CURRENT_USER so you are asking to find a subkey the same name... try
hklp = hklp.OpenSubKey("Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Aw crap, I thought I'd changed that.
Oh well, I took a well-needed break and helped my cousin install an ethernet card...haha, so hopefully now I can sit here and try this again.

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Ahh! It works!
Thank you SO much for your patience...haha. :)

I do have one more question though. I've sent this program via a link to a friend and he claims it doesn't work. He gets an error message or something. Could this be because he doesn't have the .NET framework on his computer?

The link is http://www.classic-chick.net/Aimproject.exe

EmilyBrooke
Newbie Poster
16 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You