zoukankan      html  css  js  c++  java
  • python 远程操控电脑

    import itchat
    import os
    import time
    import cv2

    sendMsg = u"{消息助手}:暂时无法回复"
    usageMsg = u"使用方法: 1.运行CMD命令:cmd xxx (xxx为命令) "
    u"-例如关机命令: cmd shutdown -s -t 0 "
    u"2.获取当前电脑用户:cap 3.启用消息助手(默认关闭):ast "
    u"4.关闭消息助手:astc"
    flag = 0 #消息助手开关
    nowTime = time.localtime()
    filename = str(nowTime.tm_mday)+str(nowTime.tm_hour)+str(nowTime.tm_min)+str(nowTime.tm_sec)+".txt"
    myfile = open(filename, 'w')

    @itchat.msg_register('Text')
    def text_reply(msg):
    global flag
    message = msg['Text']
    fromName = msg['FromUserName']
    toName = msg['ToUserName']

    if toName == "filehelper":
    if message == "cap":
    cap = cv2.VideoCapture(0)
    ret, img = cap.read()
    cv2.imwrite("weixinTemp.jpg", img)
    itchat.send('@img@%s'%u'weixinTemp.jpg', 'filehelper')
    cap.release()
    if message[0:3] == "cmd":
    os.system(message.strip(message[0:4]))
    if message == "ast":
    flag = 1
    itchat.send("消息助手已开启", "filehelper")
    if message == "astc":
    flag = 0
    itchat.send("消息助手已关闭", "filehelper")
    elif flag == 1:
    itchat.send(sendMsg, fromName)
    myfile.write(message)
    myfile.write(" ")
    myfile.flush()

    if __name__ == '__main__':
    itchat.auto_login()
    itchat.send(usageMsg, "filehelper")
    itchat.run()


    此次程序使用的环境是 python3.6 + windows10,在运行程序之前请先确保你已经安装好了 opencv-python 和 matplotlib。通过 pip install 即可安装。

    程序主要是通过使用 itchat 库来登录到微信网页端,然后通过 itchat 来发送消息和接收消息。并通过 opencv 来调用电脑的摄像头,把当前使用电脑的用户拍照下来,发送到你的微信上。至于远程关机是通过调用 os 库,发送 cmd 命名即可实现。

    发送消息「cmd shutdown -s -t 0」即可让当前的电脑关闭。

    发送消息「cap」即可调用电脑摄像头拍摄当前用户,然后把图片发送到微信上。

    当然 cmd 命名还可以做更多有趣的事,大家可以自己去网上搜索下。

  • 相关阅读:
    StreamSets学习系列之StreamSets是什么?
    [转]How to mouse hover using Blue prism on a web page
    [转]UiPath: How to Capture a Mouse Event on Hover Menus?
    [转]VB.net中 excel 的range方法
    [转]Paste from Excel into C# app, retaining full precision
    [转]uipath team svn
    [转]RPA认证 Developer UIPath Certificate,细说uipath认证学习,Online Quiz和Practical Exam项目详解
    [转]UiPath教程:UiPath及其组件介绍
    [转]Introduction
    [转]How to enable macros in Excel 2016, 2013, and 2010
  • 原文地址:https://www.cnblogs.com/daxiaren/p/9448256.html
Copyright © 2011-2022 走看看