Newbie question: getting my program to run at startup on Windows

Mark Hammond mhammond at skippinet.com.au
Tue Feb 10 21:23:10 EST 2004


Arjan Dikhoff wrote:
> Hello, I'm new to this list.
> 
> I'm trying to get my program to run automatically at startup, but so far
> no luck. I came as far as:
> 
> key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
> "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
>                 
> _winreg.SetValueEx(key, "earthclock", 0, _winreg.REG_SZ, os.getcwdu() +
> "\\EarthClock.exe")
> _winreg.CloseKey(key)
> 
> But I get "WindowsError: [Errno 5] Access is denied"
> 
> I'm probably doing something blatantly wrong. Does anyone know what it
> is?

Keys are opened with 'read' access by default.  Use:
key = 
_winreg.OpenKey(_winreg.HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 
0, _winreg.KEY_ALL_ACCESS)

And it works fine.

Mark.




More information about the Python-list mailing list