PyQt: the best way to do a "start at boot" trick for my windows program

I use PyQt to develop an application that on Windows, if installed in the settings, should start at boot.

I release this software with PyInstaller as a single executable; I do not have a proper “installer”.

What is the best way to achieve this? (= starting from download)

A possible solution is to add a link to the startup folder, but I have to do it from the software: is this possible? Other methods?

Is there a universal path to the startup folder? Do I have a rights issue?

+4
source share
2 answers

try this code (it works for me with py2exe):

import sys from PyQt4.QtCore import QSettings from PyQt4.QtGui import (QApplication, QWidget, QCheckBox, QPushButton, QVBoxLayout) RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" class MainWidget(QWidget): def __init__(self,parent=None): super(MainWidget, self).__init__(parent) self.settings = QSettings(RUN_PATH, QSettings.NativeFormat) self.setupUi() # Check if value exists in registry self.checkbox.setChecked(self.settings.contains("MainWidget")) def setupUi(self): self.checkbox = QCheckBox("Boot at Startup", self) button = QPushButton("Close", self) button.clicked.connect(self.close) layout = QVBoxLayout(self) layout.addWidget(self.checkbox) layout.addWidget(button) def closeEvent(self, event): if self.checkbox.isChecked(): self.settings.setValue("MainWidget",sys.argv[0]); else: self.settings.remove("MainWidget"); event.accept() if __name__ == '__main__': app = QApplication(sys.argv) w = MainWidget() w.show() app.exec_() 
+6
source

You can add a registry key to [HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run] with any name and value "path_to_your_exec". this will require local administrator rights, but will work for all users. The same key, but starting with [HKEY_CURRENT_USER], will not require administrator rights, but will only work for the current user. This registry path is the same for win2k..win7

+3
source

All Articles