How to track changes in specific registry key or file with Python? [closed]
2024/10/11 16:31:58
I have to write a Python script that monitors specific registry keys and files in Windows file system and execute command each time that one of them changed.
Does anybody familiar with Python package that can monitor registry and files and call a function when they changed?
Thanks
Answer
There is a _winreg library in python that reading from and writing to the Windows Registery.
from _winreg import *print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
for i in range(1024): try:n,v,t = EnumValue(aKey,i)print i, n, v, texcept EnvironmentError: print "You have",i," tasks starting at logon..."break
CloseKey(aKey) print r"*** Writing to SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
try: SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\winnt\explorer.exe")
except EnvironmentError: print "Encountered problems writing into the Registry..."
CloseKey(aKey)CloseKey(aReg)
This is an example of how reading and writing.
for more information visit: _winreg library doc
In order to this write a Listener function that executes evey timeStamp and returns a dictonary of regsiter key and their vaules , and another function for compare these dictionaries.
Because the Numpy isnt a static library(it contains .py files, .pyc files, .so files, etc), so if I want to import it to my python code which is used in an Android phone(using CLE), I should recompile …
I"m learning python, and Im trying to do this, which I thought should be trivial, but apparently, its not. $python
>>> def isTrue(data):
... "ping" in data
...
>>>…
Ive got the IF statement;if contactstring == "[Practice Address Not Available]" | contactstring == "[]":Im not sure what is going wrong(possibly the " "s?) but I keep ge…
I have an app using Django an my my model has the following field: date = models.DateTimeField(auto_now_add=True,auto_now=False)Using that I get this: June 5, 2016, 9:16 p.m.but I need something like…
I cant seem to get WeasyPrint to work on Windows with Python 3.4 or 3.5. Has anyone been able to do this? There arent forums at weasyprint.org and the IRC channel is dead. Ive been able to install …
In the normal matplotlib axes class, it is possible to set gridlines to have a certain transparency (alpha level). Im attempting to utilise this with the APLpy package using the following:fig = pyplot.…
I am doing LDA analysis with Python. And I used the following code to create a document-term matrixcorpus = [dictionary.doc2bow(text) for text in texts].Is there any easy ways to count the word frequen…
I have created a subplots grid without any spaces between the subplots, with shared x,y-axes. I only show the ticks and labels for the outer subplots. The problem is that the tick numbers overlap at th…
I want to start a thread when django project runserver successfully.
where can I put the create-thread-and-start code? Is there any hook for the django runserver?