-3

I just created simple batch script. I want to run uninstall.exe with switches like "-q" "-splash Uninstall"

Here is the code; @echo off echo This script will uninstall some features. pause SET path=C:\Program Files\Program\uninstall.exe -q -splash Uninstall START "" "%path%" pause

If I run this code it gives an error:

Windows cannot find 'C:\Program Files\Program\uninstall.exe -q -splash Uninstall'  
Make sure you typed the name correctly, and then try again.

If I remove switches, uninstall process starts normally.

So how can I use this swtiches in a batch file?

Erdogan
  • 65
  • 2
  • 15

2 Answers2

1

As an aside, don't use path as an arbitrary choice of variable name. It has a special significance in Windows (and Unix-derived systems too).

Your main problem is that you are including the switches in your quoted string, which is then treated as a whole as the executable filename. Put your quotes only around the filename, and leave the switches outside:

SET command="C:\Program Files\Program\uninstall.exe" -q -splash Uninstall
START "" %command% 

(The only reason for the quotes is the fact that the pathname contains spaces.)

Also, you don't really need to use a variable at all, but I've used one since you used one.

Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
0

I'm not quite sure if every program you come across will have a uninstall.exe file waiting for you in the C:\Program Files(place program name here)\ directory. Even if it does, you will probably have to control it from the GUI. However, looking at another stack overflow thread here, I would like to credit the users Bali C. and PA. for coming up with a possible solution to uninstall files using a batch file by using the registry key to find an uninstall file for windows programs. I will re-paste PA.'s code below:

@echo off
for /f "tokens=*" %%a in ('reg query hklm\software\Microsoft\Windows\CurrentVersion\Uninstall\ ^| find /I "%*"') do (
  for /f "tokens=1,2,*" %%b in ('reg query "%%a" /v UninstallString ^| find /I "UninstallString"') do (
    if /i %%b==UninstallString (
      echo %%d
    )
  )
)

This code will find the uninstall file for a specific program from the registry, and then it will print out the command needed to run the uninstall file. Remove the 'echo' to just run these commands when you are sure they are correct. However, even this will probably require using the program's uninstall GUI. I don't think this would be terribly inefficient. Is there any other specific reason you want to use a batch file besides efficiency?

I hope this helps!

Community
  • 1
  • 1
iRove
  • 562
  • 1
  • 9
  • 19