简体   繁体   中英

Batch file to uninstall a program

I'm trying to uninstall a program EXE via batch file and am not having any success.

The uninstall string found in the registry is as follows:

C:\PROGRA~1\Kofax\Capture\ACUnInst.exe /Workstation
C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U 
C:\PROGRA~1\Kofax\Capture\INSTALL.LOG

If I run that from CMD or batch it does nothing.

If I run C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U from CMD it will open up a dialog box to point to the INSTALL.LOG file and then proceed to uninstall.

At the end, it will ask me to click finish.

I need this to be silent, can you point me in the right direction? This is on XP and 7.

Every program that properly installs itself according to Microsoft's guidelines makes a registry entry in either HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall (for machine installs) or HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall (for user profile installs). Usually, the key for the program will be its GUID, or else the name of the program. Within that key will be an entry called UninstallString . This contains the command to execute to uninstall the program.

If you already know ahead of time what you will be uninstalling, it should be easy enough to just put that in your batch file. It gets tricky when you try to automate that process though. You can use the reg command to get data from the registry, but it returns a lot of text around the actual value of a given key, making it hard to use. You may want to experiment with using VBscript or PowerShell, as they have better options for getting data from the registry into a variable.

This might help you further.....

How to Create a script via batch file that will uninstall a program if it was installed on windows 7 64-bit or 32-bit

I've had the same problem and this is what I came up with. Before you start using this method though, you might wanna look up the name of the application on WMIC using CMD so..

First you wanna do: WMIC product > C:\\Users\\"currentuser"\\Desktop\\allapps.txt

I'd recommend to output the command to an TXT file because it's really confusing to read it in the Cmd prompt, plus is easier to find the data you are looking for.

Now what you wanna do is find the actual name of the app... If you look at the code I put in, the app name says SkypeT because skype has "™" in the end of it and the command prompt can't interpretate that as it is.

After you got the app name, just put in the find in the 4th line and substitute, a few lines which contain my examples with skype...

Also you can probably creat a variable called %APP% and not worry as much, but at it's current it works just fine...

One thing to note! with me the msi /quiet command did not work, the program would not install or uninstall so I used /passive, which lets the users see what's going on.

@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 )
)

:Status
tasklist /nh /fi "IMAGENAME eq "APP.exe" | find ":"> nul
if errorlevel = 1 goto :force
goto :Uninstall

: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
)

:DoWhile
cls
Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 (
echo Installation in progress
Goto :DoWhile
)
echo Skype is Uninstalled

:Reinstall
msiexec.exe /i SkypeSetup.msi /passive /norestart

:reinstallLoop

Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 ( 
echo Installation in progress
goto :reinstallLoop
)
echo Skype is installed

:end
cls
color 0A
Echo Done!
exit

One last thing. I used this as an Invisible EXE task, so the user couldn't interact with the command prompt and eventually close the window (I know, I know, it makes the whole echoes stupid, but it was for testing purposes).for that I used BAT to EXE converter 2.3.1, you can put everything to work on the background and it will work very nicelly. if you want to show progress to users just write START Echo "info" and replace the info with whatever you want, it will open another prompt and show the info you need.

Remember, Wmic commands sometimes take up to 20 seconds to execute since it's querying the conputer's system, so it might look like it's doing nothing at first but it will run! ;) Good luck :)

We needed a batch file to remove a program and we couldn't use programmatic access to the registry.

For us, we needed to remove a custom MSI with a unique name. This only works for installers that use msi or integrate such that their cached installer is placed in the Package_Cache folder. It also requires a unique, known name for the msi or exe. That said, it is useful for those cases.

dir/s/b/x "c:\programdata\packag~1\your-installer.msi" > removeIt.bat
set /p RemoveIt=< removeIt.bat
echo ^"%RemoveIt%^" /quiet /uninstall > removeIt.bat
removeIt.bat

This works by writing all paths for 'your-installer.msi' to the new file 'removeIt.bat' It then assigns the first line of that bat file to the variable 'RemoveIt' Next, it creates a new 'removeIt.bat' that contains the path/name of the.msi to remove along with the needed switches to do so. Finally, it runs the batch file which executes the command to uninstall the msi. This could be done with an.exe as well.

You will probably want to place the 'removeIt.bat' file into a known writable location, for us that was the temp folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM