I want to make a python code to run persistently in windows. I am trying to make a backdoor in python , and i want to add persistence to it.
Asked
Active
Viewed 599 times
-2
-
possible duplicate of: https://stackoverflow.com/questions/4438020/how-to-start-a-python-file-while-windows-starts – Krishna Chaurasia Jan 22 '21 at 11:49
-
Use [scheduler] (https://apscheduler.readthedocs.io/en/stable/) and create a .bat file with cmd like "python C:path_to_script/myscript.py" and put this file inside startup file (win+r and type shell:startup) – bilke Jan 22 '21 at 11:53
2 Answers
1
You could make a batch file and store it in startup folder to achieve such a thing,just make a batch file named whatever.bat
.then write the following code in it.
@echo off
python pathtoyourpyfile\app.py
after making the batch file,navigate to C:\Users\[your username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
and paste the batch-file here .now every time when your pc will start thhis batch-file will execute and call your python script.

Justaus3r
- 395
- 5
- 15
0
if can simply add the following code to your script. , this only works on windows!:
import getpass
import os
USER_NAME = getpass.getuser()
def add_to_startup(file_path=""):
if file_path == "":
file_path = os.path.dirname(os.path.realpath(__file__))
bat_path = r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' % USER_NAME
with open(bat_path + '\\' + "open.bat", "w+") as bat_file:
bat_file.write(r'start "" %s' % file_path)

Moetaz Brayek
- 259
- 2
- 9