Help with another key. (Almost done)!

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 16
Reputation: EmilyBrooke is an unknown quantity at this point 
Solved Threads: 0
EmilyBrooke EmilyBrooke is offline Offline
Newbie Poster

Help with another key. (Almost done)!

 
0
  #1
Mar 5th, 2006
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);

         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);

            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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help with another key. (Almost done)!

 
0
  #2
Mar 5th, 2006
Whats the problem? you didnt say if there was an error.

What is the value in the registry? Is it a delimited text?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 16
Reputation: EmilyBrooke is an unknown quantity at this point 
Solved Threads: 0
EmilyBrooke EmilyBrooke is offline Offline
Newbie Poster

Re: Help with another key. (Almost done)!

 
0
  #3
Mar 5th, 2006
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."
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help with another key. (Almost done)!

 
0
  #4
Mar 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 16
Reputation: EmilyBrooke is an unknown quantity at this point 
Solved Threads: 0
EmilyBrooke EmilyBrooke is offline Offline
Newbie Poster

Re: Help with another key. (Almost done)!

 
0
  #5
Mar 5th, 2006
Alright then. So now I have changed that part to
  1. RegistryKey hklp = Registry.CurrentUser;
  2. hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");
  3. try
  4. {
  5. Object obc = hklp.GetValue("Identifier");
  6. sw.WriteLine("Users: {0} " + obc.ToString());
  7. }
  8. catch (Exception exc)
  9. {
  10. sw.WriteLine(exc.Message);
  11. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help with another key. (Almost done)!

 
0
  #6
Mar 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 16
Reputation: EmilyBrooke is an unknown quantity at this point 
Solved Threads: 0
EmilyBrooke EmilyBrooke is offline Offline
Newbie Poster

Re: Help with another key. (Almost done)!

 
0
  #7
Mar 5th, 2006
Done, but it's still not working.
Apparently there's no way to get it to do that.
Oh well.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help with another key. (Almost done)!

 
0
  #8
Mar 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 16
Reputation: EmilyBrooke is an unknown quantity at this point 
Solved Threads: 0
EmilyBrooke EmilyBrooke is offline Offline
Newbie Poster

Re: Help with another key. (Almost done)!

 
0
  #9
Mar 5th, 2006
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.

http://www.classic-chick.net/registry.jpg
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help with another key. (Almost done)!

 
0
  #10
Mar 5th, 2006
ok that helps a lot

you need this bit of code
  1. RegistryKey hklp = Registry.CurrentUser;
  2. hklp = hklp.OpenSubKey("HKEY_CURRENT_USER\\Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users");
  3. try
  4. {
  5. string[] valnames = hklp.GetValueNames();
  6. for (int i = 0; i < valnames.count; i++)
  7. {
  8. Object obc = hklp.GetValue(valnames[i]);
  9. sw.WriteLine("Users: {0} " + obc.ToString());
  10. }
  11. }
  12. catch (Exception exc)
  13. {
  14. sw.WriteLine(exc.Message);
  15. }

See if that helps
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC