Cisco AnyConnect silent uninstall

This will:
  • detect Cisco AnyConnect 3.1 version
  • kill existing AnyConnect instance
  • stop AnyConnect service
  • uninstall AnyConnect on 32-bit and 64-bit windows

Additional libraries is needed to kill existing instance:
http://live.sysinternals.com/Tools/pskill.exe

silent-uninstall.cmd
@echo off
set sw=HKLM\SOFTWARE
set u=Microsoft\Windows\CurrentVersion\Uninstall
set n=Cisco AnyConnect Secure Mobility Client
setlocal EnableDelayedExpansion
if "%ProgramFiles(x86)%"=="" goto native
:only64bit
for /f "tokens=8 delims=\" %%a in ('^
reg query "%sw%\Wow6432Node\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\Wow6432Node\%u%\%%a" /v DisplayName > nul 2>&1
if !errorlevel!==0 (
reg query "%sw%\Wow6432Node\%u%\%%a" /v DisplayName | find "%n%" > nul 2>&1
if !errorlevel!==0 (
echo %%a | find "{"
if !errorlevel!==0 (
tasklist | find "vpnui.exe"
if !errorlevel!==0 "%~dp0pskill.exe" "vpnui.exe"
sc query vpnagent | find "4  RUNNING"
if !errorlevel!==0 net stop vpnagent
%systemroot%\system32\msiexec.exe /x %%a /qb
)
)
)
)

:native
for /f "tokens=7 delims=\" %%a in ('^
reg query "%sw%\%u%" /s ^| find "\Uninstall\"') do (
reg query "%sw%\%u%\%%a" /v DisplayName > nul 2>&1
if !errorlevel!==0 (
reg query "%sw%\%u%\%%a" /v DisplayName | find "%n%" > nul 2>&1
if !errorlevel!==0 (
echo %%a | find "{"
if !errorlevel!==0 (
tasklist | find "vpnui.exe"
if !errorlevel!==0 "%~dp0pskill.exe" "vpnui.exe"
sc query vpnagent | find "4  RUNNING"
if !errorlevel!==0 net stop vpnagent
%systemroot%\system32\msiexec.exe /x %%a /qb
)
)
)
)

endlocal
This is tested on:
anyconnect-win-3.1.05187-pre-deploy-k9.msi
b260a31b6970073d6157aca648ac5d14
875bbbdd86a65f5c5dab3e3d173fefb00b2f2e1f
ftp://ftp.a-f.ch/pub/Software/Cisco/AnyConnect%20VPN%20Client/Version%203.1.05187/