python代码实现windows10普通登录用户企业微信降级

公司的业务需求,需要使用老版本的企业微信。但是员工的电脑没有管理员权限,没法安装软件。但是企业微信经常自动更新,如果让运维一个一个的处理,累成了狗。现在根据这个需求写了个简单的脚本,实现基本的自动化。

import win32api
import os
import win32con
import requests
import time

user_name = '用户名'
pwd = '密码'

user_name1 = '用户名'
pwd1 = '密码'


# 卸载企微软件
def Uninstall_WXWork():
    # 获取企微软件安装路径
    key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'SOFTWARE\Tencent\WXWork', 0, win32con.KEY_ALL_ACCESS)
    value = win32api.RegQueryValueEx(key, "Executable")[0]
    win32api.RegCloseKey(key)
    WxWork_value = str(value).split('WXWork.exe')[0]
    # 1.获取企微卸载程序路径
    wx_uninstall_path = WxWork_value + "Uninstall.exe"
    # 2.执行卸载程序
    # os.system('start ' + wx_uninstall_path)
    s1 = os.system('PsExec.exe -u ' + str(user_name) + ' -p ' + str(pwd) + ' "' + wx_uninstall_path + '"')

    # 如果用户名密码错误
    if s1 == 1326:
        os.system('c:PsExec.exe -u ' + str(user_name1) + ' -p ' + str(pwd1) + ' "' + wx_uninstall_path + '"')
    


# 执行安装企微命令
def Install_WXWork(qw_url='http://下载服务器ip/qw.exe'):
    # 安装旧版本企微
    print(qw_url)
    psexec_url = 'http://下载服务器ip/PsExec.exe'
    qw_path = r'c:\qw.exe'
    psexec_path = r'c:\PsExec.exe'
    response_qw = requests.get(qw_url)
    response_psexec = requests.get(psexec_url)
    open(psexec_path, 'wb').write(response_psexec.content)
    open(qw_path, 'wb').write(response_qw.content)
    # 停止10s后运行安装程序
    time.sleep(10)
    s1 = os.system('c:/PsExec.exe -u ' + str(user_name) + ' -p ' + str(pwd) + ' "' + qw_path + '"')
    print(s1)
    # 如果用户名密码错误
    if s1 == 1326:
        os.system('c:/PsExec.exe -u ' + str(user_name1) + ' -p ' + str(pwd1) + ' "' + qw_path + '"')


if __name__ == '__main__':
    # 执行卸载企微
    Uninstall_WXWork()
    Install_WXWork(qw_url='http://下载服务器IP/WeCom_4.1.2.6011.exe')

以上代码根据自己的需求进行更改没问题,使用 pyinstaller封装成.exe

pyinstaller -F -w .\企微降级.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值