Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 27th, 2004, 04:21 AM
Authorized User
 
Join Date: Mar 2004
Location: Ranchi, Jharkhand, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Windows Registry

Hi All,
How to refresh registry from a VB code.

Looking for early help.

Reply With Quote
  #2 (permalink)  
Old April 27th, 2004, 08:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You do not (and can not) refresh the registry (using VB or any other language for that matter). The registry is simply a big database, once you write to it, the data is there for everyone to see (assuming they have the appropriate permission).

I assume you are asking the question because you are writing something to the registry in VB and then checking for its existence and it is not showing up. If this is the case then it may be because you have not closed the key you are working with. You need to do this to flush the data to the registry (in the same way you have to do a .Update to a database object after changing a field). When your program ends or you close VB then all the registry keys you have opened are automatically closed, thus being flushed to the registry. This might be why your program can not see the key, but when you re-run it the program can find the key.

Regards
Owain Williams
Reply With Quote
  #3 (permalink)  
Old April 27th, 2004, 11:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using the native VB SaveSetting there is no need to flash the registry because VB opens and closes the key every time. If you have the handle of an open key, you can refresh it by calling the RegFlushKey API

Marco
Reply With Quote
  #4 (permalink)  
Old April 28th, 2004, 01:45 AM
Authorized User
 
Join Date: Mar 2004
Location: Ranchi, Jharkhand, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,

marcostraf:

You are thinking in the right way, What i am trying to do, my application is running on setup prog from within itself, setup takes its own time, but in the same time prog execution proceeds as setup is running in OS as other instance, my program checks for one certain data in registry stored by the setup program and since setup is not completed by the time when program reads that key value and hence error. If i uses F5 key in between that it appears even when setup is running.
I wanted to do this by refreshing the registry.

owain:
I have not used RegFlushKey API, can you plz. five some sample code.

Regards,
Rajesh.


Reply With Quote
  #5 (permalink)  
Old April 28th, 2004, 03:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To use the RegFlushKey API call you will need to have opened the registry key by calling the RegOpenKey API call and obtaining a handle to the key, here is a simple example:
Code:
Declare Function RegOpenKey& Lib "advapi32.dll" Alias "RegOpenKeyA" _
          (ByVal hKey As Long, _
           ByVal lpSubKey As String, _
                 phkResult As Long)
Declare Function RegFlushKey& Lib "advapi32.dll" (ByVal hKey As Long)
Declare Function RegCloseKey& Lib "advapi32.dll" (ByVal hKey As Long)

Const HKEY_CURRENT_USER = &H80000001
Const ERROR_SUCCESS As Long = 0

Function FlushKey() As Boolean

    Dim lngKeyHandle                As Long

    ' Open the key.
    If RegOpenKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows", _
            lngKeyHandle) = ERROR_SUCCESS Then
        ' Flush the key (and all of it's sub keys) to disk.
        If RegFlushKey(lngKeyHandle) = ERROR_SUCCESS Then
            FlushKey = True
        Else
            FlushKey = False
        End If
    Else
        FlushKey = False
    End If
    ' Close the key.
    RegCloseKey lngKeyHandle

End Function
Also, my apologies for stating that you could not refresh the registry, Marco is right. Dan Appleman has this to say about the RegFlushKey API call in his book 'Visual Basic Programmer's Guide to the Win32 API:'
Quote:
quote:Some operating systems delay writing changes to the registry to disk in order to improve performance. This function ensures that the data has been written to disk, but should be avoided where possible as it can severely impact performance of an application.
I hope this helps.

Regards
Owain Williams
Reply With Quote
  #6 (permalink)  
Old April 28th, 2004, 02:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The windows Registry has a 'lazy flusher' mechanism, therefore most of the time there is no need to use RegFlushKey. And I do not know if RegFlushKey will flush data written by another application.
To check if a key is changed in a polling timer, you have to close and re-opeon that key every time. Or, if you really are in hardcore programming, you can wait to be notified using RegNotifyChangeKeyValue

Marco
Reply With Quote
  #7 (permalink)  
Old April 29th, 2004, 01:08 AM
Authorized User
 
Join Date: Mar 2004
Location: Ranchi, Jharkhand, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ThanX owain and marcostraf
I hope from your hints i'll be able to find the solution.

Best Regards.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows registry ivanlaw Pro VB 6 7 November 19th, 2007 12:41 PM
Windows Registry Indraja VB.NET 0 June 6th, 2007 06:55 AM
Windows Registry Editing via Java Sandz J2EE 0 February 28th, 2005 10:05 AM
Registry snowy0 VB.NET 2002/2003 Basics 1 September 8th, 2004 10:40 AM



All times are GMT -4. The time now is 12:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.