简体   繁体   English

如何使用 Python 3

[英]How to download and silent install .exe file with given URL using Python 3

I have a URL which is a download link to a software.exe file.我有一个 URL,它是一个 software.exe 文件的下载链接。 The intended operation is to use Python 3 to download the said file and then do a silent installation.预期的操作是使用 Python 3 下载上述文件,然后进行静默安装。

import ssl
from urllib.parse import urlparse
import requests

#convert to string
url = str(url) 

#convert ftp download path to http and remove chars to make it downloadable 
httpurl = re.sub("ftp://","https://",url)
print("url is: " + url)


#function to break file name from the full path
def split(downloadurl):
    p,downloadexename = os.path.split(downloadurl)
    return [downloadexename]

#Remove all the unnecessary stuff you don't need
downloadurl = httpurl.replace("'","").replace(',','').replace(":2100/FTP Folders/Software","").replace(" ","%20").strip("(").strip(")")
print("Download URL is: "+downloadurl)

down_name = os.path.basename(downloadurl)
down_dir = r"C:\Desktop"
                 
#Create folder if it doesn't exist for download as required 
if not os.path.exists(down_dir):
    os.makedirs(down_dir)
full_path = os.path.join(down_dir, down_name)

# Silent Install
subprocess.call([full_path, '/Silent'], shell=True)

It depends on what kind of installer the .exe is, but there is a high chance it already has the ability to install silently.这取决于.exe是哪种安装程序,但它很有可能已经具备静默安装的能力。 For example, InnoSetup installers (a very common type) use the parameter /SILENT .例如,InnoSetup 安装程序(一种非常常见的类型)使用参数/SILENT If you don't know the installer type, you may try running the .exe with different variants of /s , /S , /SILENT etc. -- or some variants of /?如果您不知道安装程序的类型,您可以尝试使用/s/S/SILENT等的不同变体运行.exe - 或/?的某些变体。 , --help to show command line usage. , --help显示命令行用法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM