当前位置: 编程技术>python
Python 自动安装 Rising 杀毒软件
来源: 互联网 发布时间:2014-09-04
本文导语: 不能使用时,或重新安装系统时,方便我们重新安装最新的版本. 但是每次安装都要点击好几次 Next 按钮,同时还要提供序列号,ID 等信息,我很讨厌这种重复工作,索性写一个小的脚本,让他自动安装,这样 我就可以,在安装时休息几分...
不能使用时,或重新安装系统时,方便我们重新安装最新的版本.
但是每次安装都要点击好几次 Next 按钮,同时还要提供序列号,ID 等信息,我很讨厌这种重复工作,索性写一个小的脚本,让他自动安装,这样
我就可以,在安装时休息几分钟了
脚本使用了 Python 2.3 + Com 对象,所以你的系统必须安装Python2.3或更高版本
同时必须安装 Mark Hammond's Win32all 模块
(特别感谢Mark Hammond是他开发了超级模块Win32all,同时向天才的Python 开发团队表示感谢,是他们创造了神奇的 Python 语言)
脚本的使用很简单,第一次运行时在命令行下使用 RisingInstall.py -c RisingInstall.cfg
在同目录下建立配置文件,打开它修改sn,id,path,execpath,分别填入 序列号,id号,安装路径,
以及安装程序所在的目录及安装程序名字
之后直接运行RisingInstall.Py 即可
######################################################################
# Create By WormChocolate
# RisingInstall.py Version Beta 1
# 2005/02/22 19:17 PM
# Test Wscript.Shell Object's Install Rising-Setup in Python
######################################################################
import win32com.client,time,os,sys,ConfigParser
wsh = win32com.client.Dispatch("Wscript.Shell")
def InstallRising(ConfigFileName="RisingInstall.cfg"):
if os.path.exists(ConfigFileName):
cfg = ConfigParser.ConfigParser()
cfg.read(ConfigFileName)
try:
sn = cfg.get("Install","sn")
id = cfg.get("Install","id")
installpath = cfg.get("Install","path")
execpath = cfg.get("Install","execpath")
splashsec = int(cfg.get("Program","splashsec"))
languagesec = int(cfg.get("Program","languagesec"))
itemsec = int(cfg.get("Program","itemsec"))
wshe = wsh.Exec(execpath)
pid = wshe.ProcessID
except:
print "ConfigParser faile"
sys.exit(1)
if pid != "":
wsh.AppActivate(pid)
time.sleep(splashsec)
wsh.SendKeys("{ENTER}")
time.sleep(languagesec)
wsh.SendKeys("%n")
#time.sleep(itemsec)
wsh.SendKeys("%a")
#time.sleep(itemsec)
wsh.SendKeys("%n")
#time.sleep(itemsec)
wsh.SendKeys(sn)
#time.sleep(itemsec)
wsh.SendKeys(id)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%s")
time.sleep(itemsec)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys(installpath)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%n")
wsh.SendKeys("%n")
else:
print "Config File " + ConfigFileName +" Not Found"
print "Now Auto Create This Config File Dot't Worry"
CreateCfg(ConfigFileName)
InstallRising()
def CreateCfg(cfgname):
if cfgname != "":
print "Createing Config File : "+ cfgname + "..."
contents = ["[Install]n","sn=n","id=n","path=c:\\Program Files\\rising\\Ravn","execpath = c:\\Rising17.06.exen"
"n[Program]n","splashsec=20n","languagesec=2n","itemsec=1n"]
cfg = open(cfgname,"w+t",256)
cfg.writelines(contents)
cfg.close()
print cfgname + " Create Ok..."
#----- Main -------------
if len(sys.argv) == 1 :
InstallRising()
elif len(sys.argv) == 2:
InstallRising(sys.argv[1])
elif len(sys.argv) == 3:
if sys.argv[1]=="-c" and sys.argv[2] != "":
CreateCfg(sys.argv[2])
print "Config File: " + sys.argv[2] + " Created OK..."
else:
print "Parm Error : nExample : "+sys.argv[0]+" -c ConfigFileName.cfg"
else:
print "Script Error"
但是每次安装都要点击好几次 Next 按钮,同时还要提供序列号,ID 等信息,我很讨厌这种重复工作,索性写一个小的脚本,让他自动安装,这样
我就可以,在安装时休息几分钟了
脚本使用了 Python 2.3 + Com 对象,所以你的系统必须安装Python2.3或更高版本
同时必须安装 Mark Hammond's Win32all 模块
(特别感谢Mark Hammond是他开发了超级模块Win32all,同时向天才的Python 开发团队表示感谢,是他们创造了神奇的 Python 语言)
脚本的使用很简单,第一次运行时在命令行下使用 RisingInstall.py -c RisingInstall.cfg
在同目录下建立配置文件,打开它修改sn,id,path,execpath,分别填入 序列号,id号,安装路径,
以及安装程序所在的目录及安装程序名字
之后直接运行RisingInstall.Py 即可
代码如下:
######################################################################
# Create By WormChocolate
# RisingInstall.py Version Beta 1
# 2005/02/22 19:17 PM
# Test Wscript.Shell Object's Install Rising-Setup in Python
######################################################################
import win32com.client,time,os,sys,ConfigParser
wsh = win32com.client.Dispatch("Wscript.Shell")
def InstallRising(ConfigFileName="RisingInstall.cfg"):
if os.path.exists(ConfigFileName):
cfg = ConfigParser.ConfigParser()
cfg.read(ConfigFileName)
try:
sn = cfg.get("Install","sn")
id = cfg.get("Install","id")
installpath = cfg.get("Install","path")
execpath = cfg.get("Install","execpath")
splashsec = int(cfg.get("Program","splashsec"))
languagesec = int(cfg.get("Program","languagesec"))
itemsec = int(cfg.get("Program","itemsec"))
wshe = wsh.Exec(execpath)
pid = wshe.ProcessID
except:
print "ConfigParser faile"
sys.exit(1)
if pid != "":
wsh.AppActivate(pid)
time.sleep(splashsec)
wsh.SendKeys("{ENTER}")
time.sleep(languagesec)
wsh.SendKeys("%n")
#time.sleep(itemsec)
wsh.SendKeys("%a")
#time.sleep(itemsec)
wsh.SendKeys("%n")
#time.sleep(itemsec)
wsh.SendKeys(sn)
#time.sleep(itemsec)
wsh.SendKeys(id)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%s")
time.sleep(itemsec)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys(installpath)
wsh.SendKeys("%n")
time.sleep(itemsec)
wsh.SendKeys("%n")
wsh.SendKeys("%n")
else:
print "Config File " + ConfigFileName +" Not Found"
print "Now Auto Create This Config File Dot't Worry"
CreateCfg(ConfigFileName)
InstallRising()
def CreateCfg(cfgname):
if cfgname != "":
print "Createing Config File : "+ cfgname + "..."
contents = ["[Install]n","sn=n","id=n","path=c:\\Program Files\\rising\\Ravn","execpath = c:\\Rising17.06.exen"
"n[Program]n","splashsec=20n","languagesec=2n","itemsec=1n"]
cfg = open(cfgname,"w+t",256)
cfg.writelines(contents)
cfg.close()
print cfgname + " Create Ok..."
#----- Main -------------
if len(sys.argv) == 1 :
InstallRising()
elif len(sys.argv) == 2:
InstallRising(sys.argv[1])
elif len(sys.argv) == 3:
if sys.argv[1]=="-c" and sys.argv[2] != "":
CreateCfg(sys.argv[2])
print "Config File: " + sys.argv[2] + " Created OK..."
else:
print "Parm Error : nExample : "+sys.argv[0]+" -c ConfigFileName.cfg"
else:
print "Script Error"
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。