-
Hiya,
I've made a simple program that can read certain values from a registry-key. However, I must click a button to read these values. Is there a way that my programm continously monitors this registry-key and updates my label when the value changes?
For short: When I change a value with regedit, my label must change also without me pushing a button. I know I can use a timer, but that's much to easy!
Thanks in advance.
-
I think there's no problem with using timer. Timer is the easiest. Of course there's some API, but not for watching registry changes (you always need timer or other way to keep watch).
-
I know that a timer is the most easiest way, but I like the difficult way. I want my program to work like Windows-Explorer for example. When you edit a file, you can see the changes immediately.
When I change a key using Regedit, my program must change the label also immediately.
So it's probably an API. Maybe anyone can help me which API I need and how I should use it.
Thanks!!
-
Doesn't timer do it immediately? Though nothing can be immediate.
Of course you could use GetTickCount API, it's faster than timer but much harder to use.
-
you could set up a service (activeX svr) that watches paticular keys, and have it notify you with an event (or other method) when the key change.
td.
Novacain, if your reading this, this gives me another idea for WhiteLines. Will mail you.
-
I like the idea of an activeX Service. Could you help me get started?
Thanks a lot!!
-
The basic idea is, you create an activeX.exe that exposes a some com event raising objects.
Your client app, will create one of these objects. The object has properties and methods you can set to watch certain reg keys (or for that matter file changes or pretty much any thing you want).When you get a change the event fires, and you client is notified. Saves you putting the logic in and tying up your client.
td.
-
I've never done this before, but I'm going to try. I'll get back if I can't get it working.
Thanks.
-
Hi,
Maybe, you could give me some code or examples. As I said, I've never done this before and I can't get it to work. I'm reading some articels about it, but It's going a bit slow. Could you help me out here?
Thanks very much.
-
sure.
What have you done so far/what are you reading about?
Start with the basics.
Do you know what the difference between and activeX exe and aX dll?
Do you know how to reference and use aX (COM) widgets?
Do you know about events.
btw. i really do think we should have a COM forum on the boards. Anybody else agree (seeing one way or another, thats how most of us get paid!)
td.
-
Check out the API call
Code:
Public Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" (ByVal hKey As Long, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long, ByVal hEvent As Long, ByVal fAsynchronus As Long) As Long
hint: fAsynchronus determines whether the call will not return untill change has occured...
td.
-
Yep, here's an example from the API-Guide (allapi.net)
Code:
'This program shows you how to use the RegNotifyChangeKeyValue-function
'As its name predicts, RegNotifyChangeKeyValue will notify our program
'when the registry changes.
'Follow these steps to test this program:
'1. Start this program
'2. Start Regedit.exe (located in your Windows-directory)
'3. Go to HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Registry Notification
'4. Change one of the values, located in a sub-driectory, or delete this directory
'5. You will see that our program returns from the RegNotifyChangeKeyValue
'WARNING: Playing with the registry can have serious consequences !
' If you don't know what you're doing, I advise you not to delete anything
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_NOTIFY_CHANGE_NAME = &H1 ' Create or delete (child)
Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
Const REG_NOTIFY_CHANGE_LAST_SET = &H4 ' time stamp
Const REG_NOTIFY_CHANGE_SECURITY = &H8
Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
Private Declare Function RegNotifyChangeKeyValue Lib "advapi32" (ByVal hKey As Long, ByVal bWatchSubtree As Boolean, ByVal dwNotifyFilter As Long, ByVal hEvent As Long, ByVal fAsynchronous As Boolean) As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'Create a temporary registry key
SaveSetting "Registry Notification", "Hello", "Testing", "123"
'Call the function .. This will notify us when something changes at HKEY_CURRENT_USER
RegNotifyChangeKeyValue HKEY_CURRENT_USER, True, REG_LEGAL_CHANGE_FILTER, AddressOf RegProc, False
MsgBox "Registry changed"
Unload Me
End Sub