我的脚本出了问题,但我不知道是什么问题

问题描述 投票:0回答:1

我正在尝试创建一个批处理脚本,该脚本将根据计算机操作系统和体系结构下载文件。我唯一的问题是,每当我运行批处理文件时,它都会在检查计算机使用的体系结构后关闭。我觉得它是另一个 if 语句中的 if 语句,但我不确定。 (另外,我知道它明确表示不要有模糊的标题,但我不确定更好的标题是什么。)

我的目的是有一个可运行exe文件的便携式程序,并在文件丢失时运行它。我尝试了不同的方法来检查操作系统,并尝试重新排列 if 语句,但到目前为止没有任何效果。

setlocal
for /f "tokens=4-5 delims=. " %%i in ('ver') do set WINOS=%%i.%%j
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /I "x86" > NUL && set ARCHCHECK=32BIT || set ARCHCHECK=64BIT
if %WINOS%==10.0 (
   if %ARCHCHECK%==32BIT (
      echo You are running Windows 10 on a 32 Bit architecture. Getting right files.
      powershell -Command "IInvoke-WebRequest https://example.com/example.zip -OutFile example.zip"
   if %ARCHCHECK%==64BIT (
      echo You are running Windows 10 on a 64 Bit architecture. Getting right files.
      powershell -Command "Invoke-WebRequest https://example.com/example.zip -OutFile example.zip"
if %WINOS%==6.1 (
   if %ARCHCHECK%==32BIT (
      echo You are running Windows 7 on a 32 Bit architecture. Getting right files.
      powershell -Command "(New-Object Net.WebClient).DownloadFile('https://example.com/example.zip', 'example.zip')"
   if %ARCHCHECK%==64BIT (
      echo You are running Windows 7 on a 64 Bit architecture. Getting right files.
      powershell -Command "(New-Object Net.WebClient).DownloadFile('https://example.com/example.zip', 'example.zip')"

Windows 8 等

我期望批处理脚本找到操作系统(了解要使用哪个 powershell 命令),然后找到架构(了解要下载什么版本),然后运行下载命令。实际发生的情况是,脚本将一直运行到注册表查询,然后在开始处理 if 语句之前,它会停止并关闭窗口。

batch-file cmd
1个回答
1
投票

以下是使用

WMIC
GoTO
执行检查的方法:

@Echo Off
Set "MJ="
Set "MN="
For /F "EOL=O Delims=" %%A In ('"WMIc OS Get OSArchitecture,Version 2>Nul"'
) Do For /F "Tokens=1,3-4 Delims=-. " %%B In ("%%A"
) Do Set/A "OA=%%B, MJ=%%C, MN=%%D"
If Not Defined MN (If Not Defined MJ (Echo Unsupported OS&Pause&Exit/B) Else (
    Set/A MJ=5, MN=1))
Call :v%MJ%%MN%x%OA%
Pause
Exit/B

:v51x32
Echo Windows XP, Whistler Server x%OA% Commands
GoTo :EOF

:v51x64
Echo Windows XP, Whistler Server x%OA% Commands
GoTo :EOF

:v52x32
Echo Windows NET Server, Home Server, Server 2003 x%OA% Commands
GoTo :EOF

:v52x64
Echo Windows NET Server, Home Server, Server 2003 x%OA% Commands
GoTo :EOF

:v60x32
Echo Windows Longhorn, Vista, Server 2008 x%OA% Commands
GoTo :EOF

:v60x64
Echo Windows Longhorn, Vista, Server 2008 x%OA% Commands
GoTo :EOF

:v61x32
Echo Windows 7, Server 2008 R2, Home Server 2011 x%OA% Commands
GoTo :EOF

:v61x64
Echo Windows 7, Server 2008 R2, Home Server 2011 x%OA% Commands
GoTo :EOF

:v62x32
Echo Windows 8, Server 2012 x%OA% Commands
GoTo :EOF

:v62x64
Echo Windows 8, Server 2012 x%OA% Commands
GoTo :EOF

:v63x32
Echo Windows 8.1, Server 2012 R2 x%OA% Commands
GoTo :EOF

:v63x64
Echo Windows 8.1, Server 2012 R2 x%OA% Commands
GoTo :EOF

:v100x32
Echo Windows 10, Server 2016 x%OA% Commands
GoTo :EOF

:v100x64
Echo Windows 10, Server 2016 x%OA% Commands
GoTo :EOF

您可以替换

Echo
命令或在它们及其各自的
GoTo
之间添加特定命令。

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.