Registry reader

Get help developing your code

Registry reader

Postby arcanine » Thu May 13, 2010 9:19 am

I'm trying to code a console app in c# that can read registry values

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace RegistryReader
{
    class Program
    {
        static void Main(string[] args)
        {
           
            RegistryKey reg = Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\test\\test", true);
           
            if (reg == null)
                Console.WriteLine("key not found");

            else
            Console.WriteLine(reg);
            Console.ReadLine();

        }
    }
}


here is what I have so far, I have created the key in my registry under HKEY_LOCAL_MACHINE\SOFTWARE\test I have a string in there called test with a value of 123 that I want to read from, the output from my program is key not found, this is my first c# program, and I suspect I'm missing a big part of the puzzle here
User avatar
arcanine
SD Pro 5 Star
SD Pro 5 Star
 
Posts: 1056
Joined: Mon Apr 21, 2008 2:53 pm

Re: Registry reader

Postby Finito » Thu May 13, 2010 12:32 pm

The following line
Code: Select all
RegistryKey reg = Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\test\\test", true);


Register.CurrentUser.OpenSubKey would attempt to open a registry key within HKEY_CURRENT_USER also unless you want it to be writable and i assume no because of saying 'read values' in your post, then do not need the 'true' because that makes it writable.

Therefore that line should be replaced with
Code: Select all
RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\test\\test");
Finito
SomaDev Staff
 
Posts: 425
Joined: Fri Jan 11, 2008 6:25 pm

Re: Registry reader

Postby Tiffany » Thu May 13, 2010 3:45 pm

Finito wrote:The following line
Code: Select all
RegistryKey reg = Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\test\\test", true);


Register.CurrentUser.OpenSubKey would attempt to open a registry key within HKEY_CURRENT_USER also unless you want it to be writable and i assume no because of saying 'read values' in your post, then do not need the 'true' because that makes it writable.

Therefore that line should be replaced with
Code: Select all
RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\test\\test");

If its related to a previous post then it might be a:
  • Save OldWanIP
  • Read Wan IP from Registry
  • Change it in the registry if its different than OldWanIP;
  • Restart Game.exe and/or Proxy.
  • Sleep process for 200ms - relinquish control back to windows
  • Repeat list unless there is a valid escape or >TooMany errors

So, will need the stream to also be writeable or only writeable when the WAN IP changes.

Possible Issues
There are loads of issues with this; some listed below:
Key values
Some of the service name values are editable at install time and therefore would either need a config method or assumption to read / check that the correct key / WAN IP has been received.

Delay
The delay, between checks, has to tie up with the oneperone dropping users out and the Wan IP altering. They would have already been disconnected if the Wan IP changed at the ISP but would have been held up by the oneperone / services until the timeout occurs, (if it has been set in the services, lol).

Anti-virus/firewall/anti-spam software
These need to be told that its ok to continue for the WAN IP Updater and exclude future messages.

Error Checks
if the New WAN IP cannot be found or Old WAN IP is invalid this needs to be checked or rubbish can be written to the registry. This is also a possible way to truncate the registry which can kill or at the very least maim windows until reboot.
Tiffany
SD Pro 2 Star
SD Pro 2 Star
 
Posts: 428
Joined: Sat Jan 12, 2008 1:17 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron