Rechercher une chaine de caractere et executer une commande

Fermé
windu2014 Messages postés 2 Date d'inscription lundi 29 juin 2015 Statut Membre Dernière intervention 29 juin 2015 - 29 juin 2015 à 13:38
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 - 30 juin 2015 à 08:56
Bonjour,
Je ne connais rien en scripting .bat
Je souhaite faire un batch qui me permettra de mettre a jour le BIOS en fonction d'un modèle d'ordinateur. Mon fichier de référence est msinfo32.txt.
Je voudrais qu'il cherche tout d'abord la chaine de caractère "optiplex 780" dans msinfo32.txt, si cette chaine est trouvée qu'il exécute le fichier c:\temp\bios780.exe sinon il recherche une nouvelle chaine de caractere "optiplex 990" .

Je ne sais pas si je peux combiner la commande findstr et if
Quelqu'un pourrais m'aider ?

Merci.
A voir également:

1 réponse

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
29 juin 2015 à 15:29
hello
si findstr trouve, errorlevel vaut 0, sinon 1
findstr "optiplex 780" msinfo32.txt. > NUL
if %errorlevel% EQU 0 (
c:\temp\bios780.exe
) else (
findstr "optiplex 990" msinfo32.txt. > NUL
if %errorlevel% EQU 0 (
echo optiplex 900 trouvé
)
)
1
windu2014 Messages postés 2 Date d'inscription lundi 29 juin 2015 Statut Membre Dernière intervention 29 juin 2015
29 juin 2015 à 20:33
merci dubcek

en fait j'aurai voulu un truc comme çà:

set bios780=optiplex 780
set bios790=optiplex 790
set bios980=optiplex 980
set bios990=optiplex 990
set bios7010=optiplex 7010
set bios9010=optiplex 9010
set bios9020=optiplex 9020
set biosT7000=optiplex T7000
set temppc=c:\temp\01


findstr %bios780% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\bios780.exe
) else (goto :790
)

:optiplex 790
findstr %bios790% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\bios790.exe
) else (goto : optiplex 980
)

:optiplex 980
findstr %bios980% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\bios980.exe

) else (goto :990
)

:optiplex 7010
findstr %bios7010% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\bios7010.exe

) else (goto :9010
)

:optiplex 9010
findstr %bios9010% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\bios9010.exe

) else (goto :9020
)

:optiplex T7000
findstr %biosT7000% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 (
%temppc%\biosT7000.exe

)
echo MISE A JOUR BIOS INTROUVABLE


:eof

Il y a certainement des oublis ou des choses à améliorer ?
la méthodologie est-elle cohérente ?
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
30 juin 2015 à 08:56
on doit pouvoir simplifier en évitant les else et les goto
findstr %bios780% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 %temppc%\bios780.exe
findstr %bios790% %temppc%\msinfo32.txt > NUL
if %errorlevel% EQU 0 %temppc%\bios790.exe
...
0