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

A

Arjan Dikhoff

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?

Arjan
 
M

Mark Hammond

Arjan said:
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.
 
M

Miki Tebeka

Hello Arjan,
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?
As the docs say, the default access mask for OpenKey is KEY_READ. Try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
sam=_winreg.KEY_ALL_ACCESS)

HTH.
Miki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top