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———————————-