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

Discussion in 'Python' started by Arjan Dikhoff, Feb 10, 2004.

  1. 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
    Arjan Dikhoff, Feb 10, 2004
    #1
    1. Advertising

  2. Arjan Dikhoff

    Mark Hammond Guest

    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.
    Mark Hammond, Feb 11, 2004
    #2
    1. Advertising

  3. Arjan Dikhoff

    Miki Tebeka Guest

    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
    Miki Tebeka, Feb 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    4
    Views:
    711
  2. Joost Kraaijeveld
    Replies:
    4
    Views:
    5,378
  3. Replies:
    1
    Views:
    570
  4. SMALLp

    Run Python app at startup

    SMALLp, Mar 2, 2008, in forum: Python
    Replies:
    4
    Views:
    525
    Gabriel Genellina
    Mar 5, 2008
  5. Gabriel Genellina

    Re: Run on Startup

    Gabriel Genellina, Mar 18, 2009, in forum: Python
    Replies:
    4
    Views:
    668
    Gabriel Genellina
    Mar 18, 2009
Loading...

Share This Page