iT邦幫忙

0

寫一個 判斷程是使否存在 並解除安裝的批次檔

  • 分享至 

  • twitterImage

有適過下面的批次檔

可是會出現 不應該有%%a

@Echo off
CD %cd%
:VerInstall
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
if Errorlevel = 0 (
Echo Skype is installed! )
if Errorlevel = 1 ( Echo Skype is not installed, proceding to the installation!
Ping localhost -n 7 >nul
goto :Reinstall )
)

:Force
echo We are killing the proccess... Please do not use the application during this process!
Ping localhost -n 7 > nul
taskkill /F /FI "STATUS eq RUNNING" /IM APP* /T
echo The task was killed with success! Uninstalling...
Ping localhost -n 7 > nul

:Uninstall
cls
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
set %%a=%%a: =%
msiexec.exe /x %%a /passive /norestart
)

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
simon0627
iT邦新手 2 級 ‧ 2015-11-30 11:21:00
最佳解答

你測試不會是直接貼到 命令提示字元吧
這個範例應該是需存在於 批次檔後執行才可正常執行的 (.bat)
若你想直接測試內容請吧%%a 改為%a 即可

3
蟹老闆
iT邦大師 1 級 ‧ 2015-11-30 15:20:35

沒有其它需求的話這樣就可以了

<pre class="c" name="code">
@Echo off
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "Skype(TM)"') do msiexec.exe /x %%a /passive /norestart

另外

a22063821提到:
出現 不應該有%%a

我這測試沒有問題,你可以試試把

a22063821提到:
Echo Skype is installed!

改成

a22063821提到:
Echo Skype is installed^!

這裡

a22063821提到:
Find /I "SkypeT"'

可能要確認一下是這個字串嗎?

我要發表回答

立即登入回答