Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File WMIC-bat文件菜单程序_File_Menu_Batch File_Uninstallation_Wmic - Fatal编程技术网

File WMIC-bat文件菜单程序

File WMIC-bat文件菜单程序,file,menu,batch-file,uninstallation,wmic,File,Menu,Batch File,Uninstallation,Wmic,我正在尝试编写一个批处理文件,通过选择一个数字来卸载程序。我不知道如何计算操作系统中有多少个程序,然后以菜单格式为所有程序分配数字。我不想把所有的字母都输入一个程序 将以下程序复制并通过记事本,另存为gunstall.bat @Echo off Echo This is a batch file uninstallation program. Echo Run as administrator WMIC will not work. echo. Echo The command [wmic

我正在尝试编写一个批处理文件,通过选择一个数字来卸载程序。我不知道如何计算操作系统中有多少个程序,然后以菜单格式为所有程序分配数字。我不想把所有的字母都输入一个程序

将以下程序复制并通过记事本,另存为gunstall.bat

@Echo off
Echo This is a batch file uninstallation program. 
Echo Run as administrator WMIC will not work. 
echo.
Echo The command [wmic product get name] will run.
Echo Looking up all installed programs...
echo. 
wmic product get name

echo 1. First program
echo 2. Second program
echo 3. Third program
echo 4. Fourth program
echo 5. Fifth program
echo.
@echo Pick a number: 
echo. 
choice /c:12345 

if "%errorlevel%"=="1" wmic product where name="First program" call uninstall
if "%errorlevel%"=="2" wmic product where name="Second program" call uninstall
if "%errorlevel%"=="3" wmic product where name="Third program" call uninstall
if "%errorlevel%"=="4" wmic product where name="Fourth program" call uninstall
if "%errorlevel%"=="5" wmic product where name="Fifth program" call uninstall

Echo.
Echo.

@echo First method is done. I'll go into the alternate method. 

pause
Echo Get user input - program name?
Echo.
Echo This is an alternate method 
:input
set INPUT=
set /P INPUT=Uninstall which program?: %=%
if "%INPUT%"=="" goto input
echo Your input was: %INPUT%

echo.
echo.
Echo Uninstalling... 

echo The command [wmic product where name="%INPUT%" call uninstall] will run. 


wmic product where name="%INPUT%" call uninstall

@echo If there is "no instance" errors, then the program %INPUT% was uninstalled.

pause

FOR
-循环是大多数问题的答案

一个
FOR/F
-循环可以收集所有程序并对它们进行计数

set count=0
for /F "delims=" %%A in ('wmic product get name' ) do (
  set /a count+=1
  setlocal EnableDelayedExpansion
  for %%n in (!count!) do (
    endlocal
    set product[%%n]=%%A
    echo %%n. %%A
  )
)
稍后,您可以通过从阵列访问它们

SET /p uninstallNr=Uninstall number:
setlocal EnableDelayedExpansion
ECHO !product[%uninstallNr%]!