系列文章與影片:
1.如何用BAT下載python 3.9.0,並完成靜默安裝
https://skjhcreator.blogspot.com/2022/05/batpython-390.html
影片:https://youtu.be/Jhi03Xd8e3I
2.如何用BAT下載、解壓縮、環境設定Sqlite3
https://skjhcreator.blogspot.com/2022/05/batsqlite3.html
影片:https://youtu.be/oLbVw_UGhdM
3.如何用BAT與Python下載與靜默安裝 DB Browser for SQLite
https://skjhcreator.blogspot.com/2022/05/batpython-db-browser-for-sqlite.html
影片:https://youtu.be/CGMyg7aQc7M
由於正在學習Python 與 Sqlite3,需要下載與安裝DB Browser for SQLite。因此藉由BAT 與 Python 來簡化下載與安裝。換句話說,只要點兩下,就能夠完成自動下載與安裝DB Browser for SQLite。此時的靜默安裝,並不會建立捷徑。因此需要建立一個BAT來建立捷徑。此外,利用Python Wget 套件來下載檔案。若不使用BAT,而要用Python來建立捷徑的話,需要安裝win32com的模組。然而,直接用pip install win32com 會出現錯誤訊息。若要安裝win32com的模組,則需下
$pip install pypiwin32
此時的套件大小約為12.2M。
下載檔案。解壓密碼:demo1234
教學影片:
檔案名稱:DbBrowerForSQLite3DownloadAndInstall.bat
檔案內容:
@echo off
if not exist %HomeDrive%%HomePath%\AppData\Local\Programs\Python\Python39 (
start https://skjhcreator.blogspot.com/2022/05/batpython-390.html
echo "電腦內尚未安裝Python 3.9.0。請前往下載"
pause
) else (
echo "電腦內已安裝程式,不需要安裝 Pyhon 3.9.0"
echo "安裝套件 wget"
python -m pip install wget
cd %~dp0program\
python -m DownloadDbBrowerForSQLite.py
timeout /t 5
start/wait %~dp0program\Downloads\DB.Browser.for.SQLite-3.12.2-win64.msi /qb
timeout /t 2
call %~dp0program\CreateShortCuts.bat
timeout /t 2
)
exit
檔案名稱:DownloadDbBrowerForSQLite.py
檔案內容:
import os
import wget
# 下載 DB Brower for SQLite
StopDownloadSet = set()
ReadFile = []
FileName = []
UrlPath = []
# ProgramFilePath = os.getcwd()+'\\program\\'
DownloadFilePath = os.getcwd()+'\\Downloads\\'
DownloadFileName = os.listdir(DownloadFilePath)
DownloadFileNameSet = set(DownloadFileName)
UrlPathFileName = 'UrlPath.txt'
OpenFile = open(UrlPathFileName,'r')
ReadFile = OpenFile.readlines()
for i in ReadFile:
i = i.replace('\n','')
UrlPath.append(i)
temp = i.split('/')
temp = temp[-1].replace('\n','')
FileName.append(temp)
OpenFile.close()
FileNameSet = set(FileName)
# 檢查Downloads資料夾檔案名稱與UrlPath檔案內檔案名稱,是否有同名。
StopDownloadSet = FileNameSet.difference(DownloadFileNameSet)
DownloadFileName = []
for i in StopDownloadSet:
DownloadFileName.append(i)
# 如果同名,就不下載。
for i in range(0,len(DownloadFileName)):
print("Download "+DownloadFileName[i]+". Start!")
wget.download(UrlPath[i],str(DownloadFilePath+DownloadFileName[i]))
print("Download "+DownloadFileName[i]+". OK!")
檔案名稱:CreateShortCuts.bat
檔案內容:
@ECHO OFF
TITLE 建立 DB Browser for SQLCipher & DB Browser for SQLite 捷徑
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\DB Browser (SQLCipher).lnk""):b.TargetPath=""C:\Program Files\DB Browser for SQLite\DB Browser for SQLCipher.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\DB Browser (SQLite).lnk""):b.TargetPath=""C:\Program Files\DB Browser for SQLite\DB Browser for SQLite.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
echo DB Browser for SQLCipher & DB Browser for SQLite 捷徑已建立
timeout /t 2
exit
檔案名稱:UrlPath.txt
檔案內容:
https://download.sqlitebrowser.org/DB.Browser.for.SQLite-3.12.2-win64.msi
資料來源:
1.用bat自動執行安裝軟體,不用手動按下一步
1.用bat自動執行安裝軟體,不用手動按下一步
沒有留言:
張貼留言