执行下载的.exe文件后Windows弹出“此应用无法在你的电脑上运行”错误
下载EXE文件后无法运行的问题及解决方法
问题情况
尝试下载Crystaldiskinfo.exe文件,下载成功但运行时出现错误提示:“此应用无法在你的电脑上运行”。使用的下载代码如下:
$Download_Folder ="D:/Software/" $application = "Crystaldiskinfo.exe" #New-Item -ItemType File (Join-Path $Download_Folder $application) $url = "https://sourceforge.net/projects/crystaldiskinfo/files/latest/download" $outpath = "$Download_Folder/$application" Invoke-WebRequest -Uri $url -OutFile $outpath $wc = New-Object System.Net.WebClient $wc.DownloadFile($url, $outpath)
解决方法
通过以下代码解决了该问题:
Start-Process "https://sourceforge.net/projects/crystaldiskinfo/files/latest/download" Add-Type @" using System; using System.Runtime.InteropServices; using System.Text; public class APIFuncs { [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetWindowText(IntPtr hwnd,StringBuilder lpString, int cch); [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)] public static extern Int32 GetWindowThreadProcessId(IntPtr hWnd,out Int32 lpdwProcessId); [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)] public static extern Int32 GetWindowTextLength(IntPtr hWnd); } "@ sleep 3 $w = [apifuncs]::GetForegroundWindow() $len = [apifuncs]::GetWindowTextLength($w) $sb = New-Object text.stringbuilder -ArgumentList ($len + 1) $rtnlen = [apifuncs]::GetWindowText($w,$sb,$sb.Capacity) $application_name = $($sb.tostring()) Start-Sleep -s 10 #Sends keys to current application $wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate($application_name) Sleep 1 $wshell.SendKeys('~') # ~ 代表回车键
内容的提问来源于stack exchange,提问作者Timmmsa
相关产品推荐
相关产品推荐

