Python 自動安裝 Rising 殺毒軟件
更新時間:2009年04月24日 00:07:39 作者:
平日里經(jīng)常需要重新安裝殺毒軟件,我使用的是 Rising 該軟件可以將升級后的新版本,壓縮成一個安裝包,當升級失敗造成硬盤中的 Rising
不能使用時,或重新安裝系統(tǒng)時,方便我們重新安裝最新的版本.
但是每次安裝都要點擊好幾次 Next 按鈕,同時還要提供序列號,ID 等信息,我很討厭這種重復工作,索性寫一個小的腳本,讓他自動安裝,這樣
我就可以,在安裝時休息幾分鐘了
腳本使用了 Python 2.3 + Com 對象,所以你的系統(tǒng)必須安裝Python2.3或更高版本
同時必須安裝 Mark Hammond's Win32all 模塊
(特別感謝Mark Hammond是他開發(fā)了超級模塊Win32all,同時向天才的Python 開發(fā)團隊表示感謝,是他們創(chuàng)造了神奇的 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\\\\Rav\n","execpath = c:\\\\Rising17.06.exe\n" \
"\n[Program]\n","splashsec=20\n","languagesec=2\n","itemsec=1\n"]
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 對象,所以你的系統(tǒng)必須安裝Python2.3或更高版本
同時必須安裝 Mark Hammond's Win32all 模塊
(特別感謝Mark Hammond是他開發(fā)了超級模塊Win32all,同時向天才的Python 開發(fā)團隊表示感謝,是他們創(chuàng)造了神奇的 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\\\\Rav\n","execpath = c:\\\\Rising17.06.exe\n" \
"\n[Program]\n","splashsec=20\n","languagesec=2\n","itemsec=1\n"]
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"
相關文章
關于Python?Tkinter?復選框?->Checkbutton
這篇文章主要介紹了關于Python?Tkinter復選框Checkbutton,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09
使用Pytorch訓練two-head網(wǎng)絡的操作
這篇文章主要介紹了使用Pytorch訓練two-head網(wǎng)絡的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05
在Python中用GDAL實現(xiàn)矢量對柵格的切割實例
這篇文章主要介紹了在Python中用GDAL實現(xiàn)矢量對柵格的切割實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03

