944,112 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 14605
  • C# RSS
Mar 5th, 2006
0

Opening a notepad file

Expand Post »
This is my first attempt ever at a program in C#. Here's what I have so far:

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using Microsoft.Win32;
  3.  
  4. class reg
  5. {
  6. static void Main()
  7. {
  8. RegistryKey hklm =Registry.LocalMachine;
  9. hklm=hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
  10. Object obp=hklm.GetValue("Identifier");
  11. Console.WriteLine("Processor Identifier:{0}",obp);
  12.  
  13. RegistryKey hklp =Registry.LocalMachine;
  14. hklp=hklp.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
  15. Object obc=hklp.GetValue("VendorIdentifier");
  16. Console.WriteLine("Vendor Identifier:{0}",obc);
  17.  
  18. RegistryKey biosv =Registry.LocalMachine;
  19. biosv=biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapter\\4");
  20. Object obv=biosv.GetValue("Identifier");
  21. Console.WriteLine("Bios Status:{0}",obv);
  22.  
  23. RegistryKey biosd =Registry.LocalMachine;
  24. biosd=biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  25. Object obd=biosd.GetValue("SystemBiosDate");
  26. Console.WriteLine("Bios Date:{0}",obd);
  27.  
  28. RegistryKey bios =Registry.LocalMachine;
  29. bios=bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  30. Object obs=bios.GetValue("Identifier");
  31. Console.WriteLine("System Identifer:{0}",obs);
  32.  
  33. string x = Console.ReadLine();
  34. }
  35. }

I want this program to grab these registry keys and place them into a notepad file. Right now all it does is open a dos window and place them in there. How can I go about getting them to open notepad and place them in there?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EmilyBrooke is offline Offline
16 posts
since Mar 2006
Mar 5th, 2006
0

Re: Opening a notepad file

Here is a small windows application that I threw together. It is just a modification of your code. It saves each value into the text file. Then opens it in notepad.

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using Microsoft.Win32;
  11.  
  12. namespace NP_TEST
  13. {
  14. public partial class Form1 : Form
  15. {
  16. StreamWriter sw = new StreamWriter("C:\\SysInfo");
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. RegistryKey hklm = Registry.LocalMachine;
  21. hklm = hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
  22. Object obp = hklm.GetValue("Identifier");
  23. sw.WriteLine("Processor Identifier: " + obp);
  24.  
  25. RegistryKey hklp = Registry.LocalMachine;
  26. hklp = hklp.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
  27. Object obc = hklp.GetValue("VendorIdentifier");
  28. sw.WriteLine("Vendor Identifier: ", obc);
  29.  
  30. RegistryKey biosv = Registry.LocalMachine;
  31. biosv = biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapter\\4");
  32. Object obv = biosv.GetValue("Identifier");
  33. sw.WriteLine("Bios Status: ", obv);
  34.  
  35. RegistryKey biosd = Registry.LocalMachine;
  36. biosd = biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  37. Object obd = biosd.GetValue("SystemBiosDate");
  38. sw.WriteLine("Bios Date: ", obd);
  39.  
  40. RegistryKey bios = Registry.LocalMachine;
  41. bios = bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  42. Object obs = bios.GetValue("Identifier");
  43. sw.WriteLine("System Identifer:{0}", obs);
  44. sw.Close();
  45.  
  46. Process notePad = new Process();
  47. notePad.StartInfo.FileName = "notepad.exe";
  48. notePad.StartInfo.Arguments = "C:\\SysInfo";
  49. notePad.Start();
  50. }
  51. }
  52. }

I hope thats what you meant.

-T
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Mar 5th, 2006
0

Re: Opening a notepad file

That's exactly what I need, but apparently you have a form created with yours and that's what's confusing me.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EmilyBrooke is offline Offline
16 posts
since Mar 2006
Mar 5th, 2006
0

Re: Opening a notepad file

Then just use this code.

Quote ...
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.LocalMachine;
hklp = hklp.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
Object obc = hklp.GetValue("VendorIdentifier");
sw.WriteLine("Vendor Identifier: ", obc);

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

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

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

Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "C:\\SysInfo";
notePad.Start();
Thats all you need.
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Mar 5th, 2006
0

Re: Opening a notepad file

Got it. Thanks!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EmilyBrooke is offline Offline
16 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# Classes
Next Thread in C# Forum Timeline: i need help...syntax error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC