【问题标题】:downloading and Installing msi from sharefile从共享文件下载和安装 msi
【发布时间】:2017-11-04 06:47:39
【问题描述】:

我正在尝试编写一个 powershell 脚本来从 sharefile 下载 firefox msi 并静默安装。

我终于得到了下载部分的工作。但是,安装不会。当我导航到我将 firefox msi 下载到的文件夹(C:\、C:\users\public 和我的桌面)时,我收到以下错误:

此应用无法在您的 PC 上运行

无法打开此安装包。请联系应用程序供应商以验证这是一个有效的 Windows 安装程序包。

我从 mozilla 网站下载了 exe,从 front motion 下载了 msi。

该软件所在的共享对网络上的所有人开放。

exe 和 msi 都出现相同的错误。

这是我当前的脚本:

#Download and Run MSI package for Automated install
$uri = "https://sharefile.com/app/#/home/shared/foe0295b-0fbf-4ad9-ad73-fc18d26ba705/FirefoxInstaller.msi"
$out = "c:\FireFoxInstaller.msi"
Invoke-WebRequest -uri $uri -OutFile $out
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i $out /quiet /norestart /l c:\installlog.txt"

【问题讨论】:

  • 可以手动运行脚本下载的msi吗?您的共享文件链接也以 404 结尾
  • 不,我尝试手动安装,它给出了同样的错误。该链接显示 404,因为我没有包含我的公司名称。
  • 手动下载文件有用吗?是下载不正常还是文件损坏了?
  • 是的,如果从网站下载,msi 和 exe 都可以工作。
  • 那就试试别的吧,比如 .net 网络客户端

标签: powershell windows-installer installation silent sharefile


【解决方案1】:

要获取最新版本的 Firefox,请尝试以下操作(将 Outfile 替换为您自己的有效位置);

Invoke-WebRequest -Uri "https://download.mozilla.org/?product=firefox-msi-latest-ssl&os=win64&lang=en-GB" -Outfile c:\temp\firefox.msi

要安装,我使用;

start /wait msiexec /i C:\temp\Firefox.msi /quiet

【讨论】:

    【解决方案2】:

    最近我遇到了一个类似的问题,我想将 HipChat 部署到整个公司。主要区别是我在下载之前检查软件是否已经安装并尝试再次安装,它非常简单并且兼容Windows 7和10:

    $file = 'HipChat-4.29.5.1662-win32.msi'
    $link = "https://s3.amazonaws.com/hipchat-ops/hipchat4/windows/$file"
    $soft_name = 'Hipchat'
    
    $find = Get-WmiObject -Class Win32_Product -Filter "Name = `'$soft_name`'"
    
    if ($find -eq $null) {
    
        $tmp = "$env:TEMP\$file"
        $client = New-Object System.Net.WebClient
        $client.DownloadFile($link, $tmp)
    
        msiexec /i $tmp /qn
        del $tmp
        echo "Tried installing $soft_name"
    
    } else {
        echo "ERROR: $soft_name is already installed."
        echo $find
        exit 1
    }
    
    exit 0
    

    【讨论】:

    • 很有用。但对于任何好奇/开始的人。对于通配符过滤,我会使用-Filter "Name LIKE `'$soft_name`%'" (当应用程序名称包含版本号等时有用)
    【解决方案3】:

    正如您所说,您可以选择一个 MSI,但我刚刚使用了来自 Frontmotion 的 MSI

    当我这样做时,这很有效,但如果它对你有用,请告诉我。

    #Download and Run MSI package for Automated install
    $uri = "http://hicap.frontmotion.com.s3.amazonaws.com/Firefox/Firefox-53.0.3/Firefox-53.0.3-en-US.msi"
    $out = "c:\FireFoxInstaller.msi"
    
    Function Download_MSI_FireFox_Installer{
    Invoke-WebRequest -uri $uri -OutFile $out
    $msifile = Get-ChildItem -Path $out -File -Filter '*.ms*' 
    write-host "FireFox MSI $msifile "
    }
    
    Function Install_FireFox{
    $FileExists = Test-Path $msifile -IsValid
    $DataStamp = get-date -Format yyyyMMddTHHmmss
    $logFile = '{0}-{1}.log' -f $msifile.fullname,$DataStamp
    $MSIArguments = @(
        "/i"
        ('"{0}"' -f $msifile.fullname)
        "/qn"
        "/norestart"
        "/L*v"
        $logFile
    )
    If ($FileExists -eq $True)
    {
    Start-Process "msiexec.exe" -ArgumentList $MSIArguments -passthru | wait-process
    write-host "Finished msi "$msifile
    }
    
    Else {Write-Host "File doesn't exists"}
    }
    Download_MSI_FireFox_Installer
    Install_FireFox
    

    【讨论】:

      【解决方案4】:

      我认为$msifile 分配需要移到Download_MSI_FireFox_Installer 函数之外,否则我会收到InstallFireFox 函数中路径为空的错误。

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 2021-12-06
        • 1970-01-01
        • 2016-08-26
        • 2021-12-08
        • 1970-01-01
        • 2019-01-17
        • 1970-01-01
        • 2015-10-05
        相关资源
        最近更新 更多