- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Autorun a Python script on windows startup?
Appending a Python script to windows start-up basically indicates the python script will run as the windows boots up. This can be accomplished by two step processes -
Step #1: Appending or Adding script to windows Startup folder
After booting up of the windows, it executes (equivalent to double-clicking) all the application present in its startup folder or directory.
By default, the AppData directory or folder under the current_user is hidden that enable hidden files to get it and paste the shortcut of the script in the given address or the script itself. Besides this the .PY files default must be set to python IDE else the script may end up opening as a text instead of executing.
Step #2: Appending or adding script to windows Registry
This process may be risky if not accomplished properly, it includes editing the windows registry key HKEY_CURRENT_USER from the python script itself. This registry consists of the list of programs that must execute once the user Login. Registry Path−
Below is the Python code
# Python code to append or add current script to the registry # module to modify or edit the windows registry importwinreg as reg1 importos
# in python __file__ is denoeted as the instant of # file path where it was run or executed # so if it was executed from desktop, # then __file__ will be # c:\users\current_user\desktop pth1 =os.path.dirname(os.path.realpath(__file__)) # Python file name with extension s_name1="mYscript.py" # The file name is joined to end of path address address1=os.join(pth1,s_name1) # key we want to modify or change is HKEY_CURRENT_USER # key value is Software\Microsoft\Windows\CurrentVersion\Run key1 =HKEY_CURRENT_USER key_value1 ="Software\Microsoft\Windows\CurrentVersion\Run" # open the key to make modifications or changes to open=reg1.OpenKey(key1,key_value1,0,reg1.KEY_ALL_ACCESS) # change or modifiy the opened key reg1.SetValueEx(open,"any_name",0,reg1.REG_SZ,address1) # now close the opened key reg1.CloseKey(open) # Driver Code if__name__=="__main__": AddToRegistry()
- mysqld_safe - MySQL Server Startup Script
- mysql.server - MySQL Server Startup Script
- Installing Python on Windows
- How to Install Python on Windows?
- IDE for Python programming on Windows
- Python script to open a Google Map location on clipboard?
- Upgrading MySQL on Windows
- How to set your python path on Windows?
- How to set python environment variable PYTHONPATH on Windows?
- Perl Installation on Windows Platform
- Installing MySQL on Microsoft Windows
- How to execute Python CGI Script on Apache Server?
- Run Linux Natively on Windows 10
- How to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script?
- How to Install C++ Compiler on Windows?