Opening a notepad file

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

Opening a notepad file

 
0
  #1
Mar 5th, 2006
This is my first attempt ever at a program in C#. Here's what I have so far:

  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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Opening a notepad file

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

  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
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
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: Opening a notepad file

 
0
  #3
Mar 5th, 2006
That's exactly what I need, but apparently you have a form created with yours and that's what's confusing me.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Opening a notepad file

 
0
  #4
Mar 5th, 2006
Then just use this code.

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.
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
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: Opening a notepad file

 
0
  #5
Mar 5th, 2006
Got it. Thanks!
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC