You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell脚本安装OnScreen Control应用失败求助

OnScreen Control安装脚本提示“指标文件未找到”的排查与解决方案

问题场景

执行命令powershell.exe -ExecutionPolicy Bypass -File "C:\File\To\Path\Install.ps1"后,Verbose输出显示路径变量均正确,但最终提示VERBOSE: Installation failed. Indicator file not found.。计划将该应用通过Intune的Company Portal部署,需快速定位问题并解决。

核心问题分析

  1. 指标路径逻辑错误:脚本中$indicatorFilePath指向的是目录而非具体文件,即便安装未完成,目录可能已被创建,或安装失败时目录也存在,导致判断逻辑失效。
  2. 安装参数冲突:/S是Inno Setup安装包的静默参数,/v/qn是MSI安装包的参数,混用会导致安装包无法正确解析指令,实际安装未完成。
  3. Intune部署上下文不兼容:脚本中的自动提权逻辑在Intune环境下冗余(Intune默认以系统权限运行),反而可能导致进程上下文混乱;$MyInvocation.MyCommand.Definition在系统上下文下可能无法正确获取脚本路径。
  4. 未处理后台安装进程:部分安装包会启动子进程完成后续配置,Start-Process -Wait仅等待主进程结束,此时指标文件可能尚未生成,导致误判失败。

解决方案与修正脚本

关键优化点

  • 移除冗余提权逻辑,适配Intune系统权限上下文
  • 将指标路径改为检查核心可执行文件(而非目录)
  • 修正安装参数,匹配OSC安装包的实际格式
  • 增加超时等待逻辑,兼容后台安装进程
  • 结合进程退出代码与指标文件双重验证安装结果

修正后的脚本

$VerbosePreference = "Continue"

# Intune默认以系统权限运行,无需手动提权
Write-Verbose "Script running in system context (Intune deployment)."

# 定义安装成功的核心指标文件(替换为实际存在的可执行文件)
$indicatorFilePath = "C:\Program Files (x86)\LG Electronics\OnScreen Control\bin\OSC.exe"

# 使用PSScriptRoot获取脚本目录(PowerShell 3.0+兼容,适配Intune环境)
$scriptDir = $PSScriptRoot
Write-Verbose "Script directory: $scriptDir"

$installerPath = Join-Path -Path $scriptDir -ChildPath "OSC_9.23.exe"
Write-Verbose "Installer Path: $installerPath"

# OSC安装包为Inno Setup格式,使用/S参数静默安装
$installArgs = '/S'
Write-Verbose "Installation arguments: $installArgs"

if (Test-Path $installerPath) {
    Write-Verbose "Installer file found. Starting installation..."
    try {
        $installProcess = Start-Process -FilePath $installerPath -ArgumentList $installArgs -NoNewWindow -Wait -PassThru -ErrorAction Stop
        
        # 先检查安装进程退出代码(0为正常)
        if ($installProcess.ExitCode -ne 0) {
            Write-Verbose "Installation failed with exit code: $($installProcess.ExitCode)"
            exit 1
        }

        # 循环等待指标文件生成,设置5分钟超时
        $timeout = 300
        $elapsed = 0
        while (-not (Test-Path $indicatorFilePath) -and $elapsed -lt $timeout) {
            Write-Verbose "Waiting for indicator file... Elapsed: $elapsed seconds"
            Start-Sleep -Seconds 10
            $elapsed += 10
        }

        if (Test-Path $indicatorFilePath) {
            Write-Verbose "Installation successful. Indicator file found."
            exit 0
        } else {
            Write-Verbose "Installation failed. Indicator file not found after $timeout seconds."
            exit 1
        }
    } catch {
        Write-Verbose "Installation failed: $_"
        exit 1
    }
} else {
    Write-Verbose "Error: Installer file not found at path: $installerPath"
    exit 1
}

额外验证步骤

  1. 手动执行OSC_9.23.exe /S,确认静默安装是否正常完成,记录实际安装路径与核心文件位置
  2. 在Intune测试环境中部署修正后的脚本,查看日志输出是否正常
  3. 若仍有问题,可添加日志记录到本地文件(如C:\Windows\Temp\OSC_Install.log),便于排查具体错误

内容的提问来源于stack exchange,提问作者Unbuckle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:18:16