import winreg as wr
def getAutoRun():
root1 = wr.ConnectRegistry(None,wr.HKEY_LOCAL_MACHINE)
root2 = wr.ConnectRegistry(None,wr.HKEY_CURRENT_USER)
result = {}
try:
targ = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
print("****reading from ",targ,"****")
key1 = wr.OpenKey(root1,targ)
key2 = wr.OpenKey(root2,targ)
cnt=0
try:
for i in range(1024):
try:
n,v,t=wr.EnumValue(key1,i)
result[n]=v
cnt+=1
except EnvironmentError:
break
for i in range(1024):
try:
n,v,t=wr.EnumValue(key2,i)
result[n]=v
cnt+=1
except EnvironmentError:
break
finally:
wr.CloseKey(key1)
wr.CloseKey(key2)
finally:
wr.CloseKey(root1)
wr.CloseKey(root2)
return result
def main():
print(getAutoRun())
if __name__=="__main__":
main()