Thread: Registry, Regedit

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    59

    Registry, Regedit

    I have done an application where you will have to enter a Username and a password in order to enter the program...

    So a panel with 2 textboxes is promted for this.

    Now when you have entered the correct user and password, I dont want this panel to promt anymore, so I have heard about that I should work with the registry in order to do this. To somehow write to the registry and then check the registry everytime the application starts if the the user and password exists there etc...

    More than this I dont know.

    So what I wonder is what the correct way is to do this. I have never made any call write/read to the registry so I am new to this part.

    I would be very happy for a beginning assistance on this part.
    The first thing should be that if the correct user and password is written, I would write something to the registry ?

    Thank You...
    Last edited by franse; 01-27-2009 at 05:33 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Another, perhaps simpler option is to use an ini or configuration file which I believe should be stored in Documents and Settings/username/Application Data/.. folder (search MSDN to find out how to know what this folder is called).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I must ask here before checking up because I have thought about something simular but as the path is for example:
    C:\\Documents and Settings\\username\\Application Data\\..

    There will be a problem if one computer uses D:\\ and another R:\\ etc... I would never know where the system is installed.

    However when googling I did find this wich looks very interesting about the "Registry".
    It is shown how to "Creating a New Registry Key and Value". Perheps this could be a way to do it.
    The "Registry" is always the "Registry" and you does not need to know about any path if I have understood it right and makes it more portable ?

    http://www.codeguru.com/columns/dotn...9#createRegKey

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I have tried to follow an example to "Create a New Registry Key and Value".
    This code compiles and when running the code, it adds a "My Product" like this:

    HKEY_CURRENT_USER\\Software\\My Product

    Code:
    RegistryKey^ currentUser;
    RegistryKey^ softwareKey;
    
    	 try
    	 {
    	 RegistryKey^ currentUser = Microsoft::Win32::Registry::CurrentUser;
    	 RegistryKey^ softwareKey = Microsoft::Win32::Registry::CurrentUser->CreateSubKey("Software\\My Product");
    
    	 softwareKey->SetValue("Description", "Description of my product");
    	 softwareKey->SetValue("Version", "1.42");
    
    	 }
    		 catch(Exception^ ex)
    		 {
    			 MessageBox::Show(ex->Message);
    		 }
    		 __finally
    		 {
    			 if(softwareKey) softwareKey->Close();
    			 if(currentUser) currentUser->Close();
    		 }
    Last edited by franse; 01-27-2009 at 07:16 PM.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    For this line:

    Code:
    softwareKey->SetValue("Description", "Description of my product");
    How would it be possible to get the string for the first argument: "Description"

    How would it be possible to call this with syntax, ex: softwareKey->GetValue etc...
    If I can do this too, I beleive I have created a good way to do this as "Description" in Regedit is ReadOnly ?

    Thank you

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    What is the point of a password if you don't have to enter it?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    61
    yes.it's main purpose is make your information secure right?

  8. #8
    The larch
    Join Date
    May 2006
    Posts
    3,573
    What is the point of a password if you don't have to enter it?
    Don't you let your browser remember passwords for you? As long as my computer is safe the password keeps my data inaccessible from elsewhere while not getting in my way. (BTW, where and how do they store the passwords? It might be a good idea to do it in a similar way.)

    If the data is only accessible from my computer anyway a password that won't be asked has less purpose. What you might want instead is make it optional whether the password will be asked or not, so the user can decide how much security they like.

    I must ask here before checking up because I have thought about something simular but as the path is for example:
    C:\\Documents and Settings\\username\\Application Data\\..

    There will be a problem if one computer uses D:\\ and another R:\\ etc... I would never know where the system is installed.
    There should be functions to find out the names of such special directories, after all applications do use them.
    Last edited by anon; 01-28-2009 at 03:51 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I think that your first suggestion for me is the moste interesting one after all where the portability will work for "all" systems.

    To create an encrypted file out of user/password.
    If I assume for the first step to save this encrypted file to C:\\

    How do you go about create an encrypted file out of this information. I dont know how this is done really. I suppose the user/password is encrypted but C++ can also decrypt the file to see that the user/password is correct.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    I don't really understand what you're trying to do, but perhaps this code for Encrypting and Decrypting Registry Data using Microsoft's DPAPI (Data Protection API) might be helpful?

  11. #11
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by anon View Post
    There should be functions to find out the names of such special directories, after all applications do use them.
    System::Environment::GetFolderPath()

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    Ok!

    I use XP Proffessional and I have tried this code out:
    Code:
    System::Environment::GetFolderPath(Environment::SpecialFolder::System)
    This gives me: "C:\WINDOWS\system32"

    The very important question here because I have to know about the portability of this command
    regarding the systems below.

    Will this command also work for the systems below if the code is running on them ?

    XP Proffessional
    XP Home Edition
    Windows Vista
    Windows 98
    Windows ME
    Windows NT
    Windows 2000
    Windows server 2003

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why not ask Microsoft?

    Quote Originally Posted by MSDN
    Platforms
    Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    I am not sure if this is very easy to ask them, if they have any support for this regarding programming like a forum ?
    I can only find support and contact us but they should only be for products itself etc... but
    are not sure.

    Perheps however I can ask them..

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by franse View Post
    I am not sure if this is very easy to ask them, if they have any support for this regarding programming like a forum ?
    I can only find support and contact us but they should only be for products itself etc... but
    are not sure.

    Perheps however I can ask them..
    I think what tabstop was trying to say is that you don't have to "ask" as much as simply read their documentation of the function. google for "msdn getfolderpath".
    The first link that comes up is this:
    http://msdn.microsoft.com/en-us/libr...olderpath.aspx

    Around two thirds down the page is a heading called "Platforms", and it lists the OS's that support this particular function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Efficient registry use?
    By bennyandthejets in forum Windows Programming
    Replies: 6
    Last Post: 09-28-2003, 06:28 PM
  2. Registry
    By gvector1 in forum C# Programming
    Replies: 0
    Last Post: 07-30-2003, 04:02 PM
  3. how to edit the registry
    By jverkoey in forum Windows Programming
    Replies: 3
    Last Post: 03-28-2003, 04:20 AM
  4. LOGFONT struct & Registry :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 05-27-2002, 03:38 PM
  5. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM