python 自动安装软件脚本(草稿版)

引用了pamie中的函数。

功能实现:自动安装指定的软件。目前这个只是概念阶段,能够实现的就是自动点击D:/Share/cut/wxPython/LoginAnySetup0942cn.exe 这个软件的第一个下一步(如果是中文操作系统,需要修改‘&Next >’为正确的值)。

 

## start -------------------------------autoinstall.py----------------------------------

# -*- coding: utf-8 -*- #

import win32ui,win32con,pyHook,pythoncom,win32gui,win32api,wx,os
from win32api import VkKeyScan
from win32gui import PostMessage
import win32con as w
import time
import struct
import ConfigParser
import win32com.client


def _buildWinLong(high, low):
    '''Build a windows long parameter from high and low words.
    See http://support.microsoft.com/support/kb/articles/q189/1/70.asp
    '''
    # return ((high << 16) | low)
    return int(struct.unpack('>L',
                             struct.pack('>2H',
                                         high,
                                         low)) [0])

def _sendNotifyMessage(hwnd, nofifyMessage):
    '''Send a notify message to a control.'''
    win32gui.SendMessage(win32gui.GetParent(hwnd),
                         win32con.WM_COMMAND,
                         _buildWinLong(nofifyMessage,
                                       win32api.GetWindowLong(hwnd,
                                                              win32con.GWL_ID)),
                         hwnd)

def readConfig(ConfigFileName="Install.cfg"):
    if os.path.exists(ConfigFileName):
        cfg = ConfigParser.ConfigParser()
        cfg.read(ConfigFileName)
        try:
            initDelay = cfg.get("BaseConfig","initDelay")
            startupTimeout = cfg.get("BaseConfig","startupTimeout")
            idleTimeout = cfg.get("BaseConfig","idleTimeout")
            totalTimeout = cfg.get("BaseConfig","totalTimeout")
           
            hotspot = cfg.get("Click","hotspot")
        except:
            print "ConfigParser faile"
            sys.exit(1)
    print initDelay,startupTimeout,idleTimeout,totalTimeout,hotspot
    return 0

def _getButtonHwnd(WindowHwnd):
    buttonHwnd = win32gui.FindWindowEx(WindowHwnd,0,'Button','&Next >')
    return buttonHwnd

readConfig()

FileName = r'D:/Share/cut/wxPython/LoginAnySetup0942cn.exe'
try:
    win32api.WinExec(FileName,win32con.SW_SHOWNORMAL )
except:
    raw_input('Exception!..Press Enter to exist')
time.sleep(2)

CurActivePyCWnd = win32ui.GetForegroundWindow()
CurActiveWindowHwnd = CurActivePyCWnd.GetSafeHwnd()
##CurActiveWindowHwnd = 16057704
ClikButtonHwnd = _getButtonHwnd(CurActiveWindowHwnd)

#print ClikButtonHwnd
_sendNotifyMessage(ClikButtonHwnd, win32con.BN_CLICKED)


##end -------------------------------autoinstall.py----------------------------------


##end -------------------------------Install.cfg----------------------------------

[BaseConfig]
initDelay = 5
startupTimeout = 60
idleTimeout = 45
totalTimeout = 300

[Click]
hotspot = &finish|&done
##end -------------------------------Install.cfg----------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值