So here is my code
wmic product get name > "programs.txt"
FOR /f %%a IN (programs.txt) DO (
pause
echo %%a
set /p variable= Delete %%a?
pause
IF "%variable%" == "yes" (
wmic product where name="%%a" call uninstall
cls
) ELSE (
cls
)
)
I am trying to make a program where it will display the installed programs and ask if they want to uninstall them. The code runs fine up to the for loop but then it just quits. I tried it with @echo on and it just outputs the code but doesn't run it. any help would be great
[EDIT] Just to explain a bit more when I run the code everything runs fine up till the for loop and then it gets messed up. It won't even run the pause after the for loop it just ends.
The issue is with how you are creating your text file. WMIC output is Unicode. When the For loop tries to read it, it opens it as a ANSI (default) file. This results in odd behavior.
Instead of redirecting your output, /output
it like this:
wmic /output:"uniprogs.txt" product get name
Then you have to convert it from Unicode to ANSI/ASCII with the TYPE command like this:
TYPE uniprogs.txt > ansiprogs.txt
Now run your for loop on ansiprogs.txt and all should be good.