Important alert: (current site time 7/16/2013 1:47:04 AM EDT)
 

winzip icon

[Updated]Registry Access Class Module

Email
Submitted on: 11/13/2004 6:46:32 PM
By: Aleksandar Ruzicic 
Level: Beginner
User Rating: By 26 Users
Compatibility: VB 6.0
Views: 56402
 
     With this class module you can access windows's registry base and edit String, DWORD or Binary data type. List of functions (in class): -ReadString -WriteString -ReadDWORD -WriteDWORD -ReadBinary -WriteBinary -KillValue -ValueExists -EnumValues -KeyExists -CreateKey -KillKey -EnumKeys -HasSubKeys -ExportToReg -ImportFromReg -isBinValid Enjoy! Update: fixed some bugs and added new function...
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/14/2004 4:06:27 AMSteve

Cool - the first registry read/write module that supports to properly read and write binary values. Thanks for that. 5 globes. :-)
(If this comment was disrespectful, please report it.)

 
11/14/2004 4:08:15 AMSteve

Some English documentation would be nice, though ... ;-)
(If this comment was disrespectful, please report it.)

 
11/14/2004 12:44:52 PMAleksandar Ruzicic

@Steve:
Sorry, i forgoted for that ;)
By the way, my english is very poor.

It will be in next post, i promes...
(If this comment was disrespectful, please report it.)

 
11/14/2004 12:45:23 PMAleksandar Ruzicic

Sorry, i forgoted for that ;)
By the way, my english is very poor.

It will be in next post, i promes...
(If this comment was disrespectful, please report it.)

 
1/16/2005 2:09:46 PMMassaker RAT

The only thing u could do better is to put the documentation in english, everything is just GREAT, many thnx, 5 globes
(If this comment was disrespectful, please report it.)

 
4/8/2005 4:01:13 PMAleksandar Ruzicic

i forgot to say that it's now documented on english ;)

and, please vote if you like it :D
(If this comment was disrespectful, please report it.)

 
5/20/2005 4:06:27 AM

Go on Share Excellent Code!
it's perfet code...
Go on coding like this.
Good Job! Thanx for sharing it, you have 5 * from me.
(If this comment was disrespectful, please report it.)

 
5/31/2005 12:45:32 PM

I cannot get KillValue to delete a specific value...
WriteString and ValueExists work nice though.
(If this comment was disrespectful, please report it.)

 
7/27/2005 1:38:40 PMjason

This is a very good class. I wish I had created it. Very usable and easy to understand. Thank you
(If this comment was disrespectful, please report it.)

 
8/1/2005 11:55:52 AMSchmendrick

Almost perfect! (I cant get KillValue to work either) 4 ballz!
(If this comment was disrespectful, please report it.)

 
8/21/2005 6:07:30 AME. Parkes

There's an error in the BinToStr function - the zero should be added before the existing hex value if its length is less than 2, not after. { If (Len(tStr) = 1) Then tStr = tStr & "0" } should become { If (Len(tStr) = 1) Then tStr = "0" & tStr }
(If this comment was disrespectful, please report it.)

 
11/14/2005 8:56:11 AMfrostbyte2k2

There is one problem, when i try to retrieve a value from the registry, it adds me some bad letters, when i try to use ReadString !
(If this comment was disrespectful, please report it.)

 
1/3/2006 1:54:10 PMSteven Atkiss

Thankyou for this, I've recently started exploring Registry functions, and have viewed lots of code, not only is your code the shortest, but the easiest for me to understand. I dont normally use other peoples code, I like to learn from it. Excellant and thankyou for your help... 5 globes from this man.
(If this comment was disrespectful, please report it.)

 
1/9/2006 11:36:51 PMDiego de la Fuente

Hy.Like "frostbyte2k2" i have problems when I try to read an alfanumeric value from the Registry. It adds some trahs chars at the end.
If I read it to a text Box i don´t have any problem, but if I try to read it to a variable I have that bad chars.
(If this comment was disrespectful, please report it.)

 
1/24/2006 6:39:13 PMDonald Schelle

A little overkill for what I need; but, this does the trick. Thank you for wrapping up these very useful functions in such a nice class object.
(If this comment was disrespectful, please report it.)

 
1/25/2006 11:43:20 AMDonald Schelle

Frostbyte2k2, I just ran into the ReadString bug. Apparently the returned string from the RegQueryValueEx function sometimes returns a bunch of characters after the first Null. This shouldn't happen. To fix the problem replace the line:

{ReadString = Left$(sData, Len(sData) - 1}

in the ReadString function with

{ReadString = Left$(sData, InStr(1, sData, Chr$(0)) - 1) 'returning readed value}

This will force the function to look for the FIRST null in the returned value and snip everything after it. I've sent a modified file to the author with the bugfix implemented. I hope that he updates this page soon.

Still a great piece of code though.
(If this comment was disrespectful, please report it.)

 
2/10/2006 10:57:25 PMInuya5ha

EXCELLENT!!! No runtime errors at all, finally somone who worked properly on something in this site.
(If this comment was disrespectful, please report it.)

 
2/11/2006 4:06:42 PMHardStream Software Development

Whahoo!! Finally a COMPLETE registry class... All those other modules and classes are incomplete and miss functions I need. This one has it all, and most important, they all work!! Another 5 balls for this one :D
(If this comment was disrespectful, please report it.)

 
3/14/2006 7:23:38 PMAleksandar Ruzicic

new version (2.07) is available at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=64664&lngWId=1
the
reason why i posted on diferent place (and with different name) is that i forgot my password :)
Injoy in new version and please notify me if you find any bugs...
btw, thanks on comments and votes!
and about that KillValue thingy it works for me like it should, but i haven't tested it yet on 2000 (when i was wrote and debugged that function i was using win98 and since the i never used it :p) it may have to do something with permissions... will check that whan i got some spare time...
(If this comment was disrespectful, please report it.)

 
4/17/2006 12:12:47 PMleo

There is a little concept ERROR in function ReadString() when you get the data, because you should use the parameter "lDuz" or "lpcbData" to get the data, because this parameter retrives the length of the returned saved value instead of looking for the FIRST null in the returned value and snip everything after it.
I know it's a little error but who knows if some program use chr(0) caracters in its values ...

Replace the line:

ReadString = Left$(sData, Len(sData) - 1)

With this other:

ReadString = Left$(sData, lDuz)

this is the complete description of this parameter in API-Guide 3.7:

Points to a variable that specifies the size, in bytes, of the buffer pointed to by the lpData parameter. When the function returns, the variable pointed to by the lpcbData parameter contains the number of bytes stored in the buffer. This parameter can be NULL, only if lpData is NULL.

the rest is simply perfect!
5 Globes!

Regards

(If this comment was disrespectful, please report it.)

 
7/13/2006 1:26:46 PMYam Sapkota

hello , when i write dword value in registry it simply put 49 for 1 50 for 2 etc ,, how can i write 1..
eg..RegSetValueEx nKey, "NoActiveDesktop", 0, REG_DWORD, 1, 4
here 1 is the value but it saved as 49 decimal.. thanks
(If this comment was disrespectful, please report it.)

 
7/28/2006 9:53:37 AMPredator

Simply perfect and complete! 5 *****
(If this comment was disrespectful, please report it.)

 
11/1/2006 5:26:57 PMadam

I'm feeling kinda stoopid right now. I can't seem to get it to work. this is the code i used, but I keep getting an "Object variable or With block variable not set" error:

Dim reg As clsRegistryAccess
Dim strValue As String

strValue = reg.ReadString("HKLM\SOFTWARE\Name", "StringKeyName")
(If this comment was disrespectful, please report it.)

 
11/16/2006 10:02:08 PMMatty

You had it close adam, Try this...
Dim reg As New clsRegistryAccess
Hope this helps :)
(If this comment was disrespectful, please report it.)

 
3/23/2007 1:36:15 AMRuben

Very nice class, thanks for sharing!
(If this comment was disrespectful, please report it.)

 
6/24/2008 9:54:11 PMCowggodd

AWESOME CODE! exactly what I needed! I am running XP tho and I can't get the killvalue to work but otherwise fantastic!
(If this comment was disrespectful, please report it.)

 
9/2/2009 7:37:25 PMacdc

ofcourse the killvalue doesnt work! it executes the RegOpenKeyEx api function with read only permissions :D
Just replace KEY_READ with KEY_ALL_ACCESS
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.