S'il vous plaît voir les codes 2 échantillons:Quelqu'un peut-il s'il vous plaît donner une explication à ces différentes sorties
@ECHO off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" <CheckOS.txt> StringCheck.txt
If %ERRORLEVEL% == 0 (
Echo "This is 32 Bit Operating system"
set ProgFileDir=%ProgramFiles%
) ELSE (
Echo "This is 64 Bit Operating System"
set ProgFileDir=%ProgramFiles(x86)%
)
del checkos.txt
del stringcheck.txt
echo ---------------
echo "%ProgFileDir%"
echo ----------------
pause
Cela me donne une mauvaise sortie:
"This is 64 Bit Operating System"
---------------
"C:\Program Files (x86" <==Notice how the closing brace is trimmed
----------------
Press any key to continue . . .
Si je change la position de la déclaration set ProgFileDir=%ProgramFiles(x86)%
en dehors du support:
@ECHO off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" <CheckOS.txt> StringCheck.txt
If %ERRORLEVEL% == 0 (
Echo "This is 32 Bit Operating system"
set ProgFileDir=%ProgramFiles%
) ELSE (
Echo "This is 64 Bit Operating System"
)
del checkos.txt
del stringcheck.txt
set ProgFileDir=%ProgramFiles(x86)%
echo ---------------
echo "%ProgFileDir%"
echo ----------------
pause
-je obtenir le résultat correct:
"This is 64 Bit Operating System"
---------------
"C:\Program Files (x86)" <== with the closing brace
----------------
Press any key to continue . . .
Qu'est-ce que je fais de mal ici? J'exécute ce fichier de commandes sur Windows 7 64 bits OS.
En plus de votre question, vous pouvez simplifier le code en détectant la variable système sans créer 2 fichiers temporaires. [http://ss64.com/nt/syntax-64bit.html](http://ss64.com/nt/syntax-64bit.html]] – enjoying