2

This program should write another program into the Run key. It does that but the program doesn't start itself.

from winreg import *
import os
import time
aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
try:
   print ("Setting up registry.")
   SetValueEx(aKey,"Reminder",0, REG_SZ, ("%s\writereminder.pyw" % os.path.dirname(os.path.realpath(__file__))))

   print ("Success!")
except EnvironmentError:
    print ("It didn't work")
CloseKey(aKey)
CloseKey(aReg)
time.sleep(7)
Bellerofont
  • 1,081
  • 18
  • 17
  • 16
Zusor
  • 88
  • 6
  • Check out if this solves your problem http://stackoverflow.com/questions/8876330/how-do-i-add-a-python-script-to-the-startup-registry – Zeekite Feb 02 '17 at 15:39
  • `SetValueEx` isn't documented as throwing an exception when it fails - have you actually checked the registry to see that the value was written properly? – Mark Ransom Feb 02 '17 at 19:05

0 Answers0