- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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()
- Related Articles
- Run a Script on Startup in Linux
- 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?
- How to set your python path on Windows?
- How to execute Python CGI Script on Apache Server?
- How to set python environment variable PYTHONPATH on Windows?
- Upgrading MySQL on Windows
- What is the Best Way to Install Python on a Windows 10 Computer?
- How to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script?
- Why does Python sometimes take so long to start on Windows?
- Implement a Counter in Bash Script on Linux