因為轉行 每個月都要更新chrome 給各部門
且在加入AD之後 在一般管理者取得管理者權限
故寫個小程式 不用切換到管理者進行安裝
以方便可以派發
內容:
會先取回已安裝的chrome版本
在針對你要裝的版本和現在的以安版本進行比對判斷
如你要裝的版本比較新,才需要安裝
回先移除 在安裝新版本
如果要安裝版本 比較舊 就不安裝
程式如下:
from win32com.client import Dispatch
from pkg_resources import parse_version
import os
import time
def get_version_via_com(filename):
parser = Dispatch("Scripting.FileSystemObject")
version = parser.GetFileVersion(filename)
return version
if __name__ == "__main__":
path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
v1=get_version_via_com(path)
print("chrome Installed version is ",v1)
with open(r'v2.txt', 'r') as f:
i = 0
for line in f:
st[i]=line
i+= 1
f.close()
v2=st[0]
print("chrome Uninstalled version is ",v2,"\n")
filepath = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
if parse_version(v1) < parse_version(v2):
print("Installed version < Uninstalled version")
os.system("TASKKILL /IM chrome.exe /F")
if os.path.isfile(filepath):
curr_path=os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\"+v1+"\\Installer\\")
#print("RUNAS /USER:test \'C:\\Program Files\\Google\\Chrome\\Application\\"+v1+"\\Installer\\setup.exe -uninstall --force-uninstall --multi-install --chrome --system-level\'")
curr_path = os.getcwd()
print (curr_path)
os.system("RUNAS /USER:"+st[1]+ " \"C:\\Program Files\\Google\\Chrome\\Application\\"+v1+"\\Installer\\setup.exe \/quiet -uninstall --force-uninstall --multi-install --chrome --system-level\"")
os.system("dir")
time.sleep(3)
else:
curr_path=os.chdir("C:\\Program Files (x86)\\Google\\Chrome\\Application\\"+v1+"\\Installer\\")
#print("RUNAS /USER:test \'C:\\Program Files (x86)\\Google\\Chrome\\Application\\"+v1+"\\Installer\\setup.exe -uninstall --force-uninstall --multi-install --chrome --system-level\'")
curr_path = os.getcwd()
print (curr_path)
os.system("RUNAS /USER:"+st[1]+" \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\"+v1+"\\Installer\\setup.exe \/quiet -uninstall --force-uninstall --multi-install --chrome --system-level\"")
time.sleep(5)
os.system("RUNAS /USER:"+st[1]+" /savecred \"C:\\temp\\ChromeSetup.exe\"")
elif parse_version(v1) > parse_version(v2):
print("Installed version > Uninstalled version\n")
print("newchrome will not install")
else:
print("Installed version equal Uninstalled version\n")
print("new chrome will not install")
time.sleep(5)
v2檔案(會把你要安裝版本的版號 和管理者帳號寫在v2檔案)如下:
114.0.5735.167
test1234
第一是你要安裝的版本
第2是你管理者帳號
留言列表