Question : scripted uninstalls

Hello experts,

I am writing a script to uninstall some programs and i want to make sure i properly verify things before whacking the processes and file dirs.

So far  i am doing a simple 'taskkill /F /IM app1.exe' to shut down the app, but is there a way to verify if this app is running before i try to shut it down? there are many great ways I've found on the web to verify if a task is running such as the tasklist command then outputting it to a file and reading the file to see if app1.exe exists, etc. but i don't want to spend to much time over engineering this as the requirement is simple, check to see if the app is running, if so, kill it before whacking the file dirs.

Additionally, (before whacking the file dirs if they still exist) i need to uninstall the program from Add/Remove and for that i am using a command similar to this.. 'MsiExec.exe /I{91588D66-6636-47D9-ACC2-9AB9721CD1F4} '

My next question, is how would i go about checking to see if this app is actually installed before trying to fire up the uninstaller?

Thanks for all your help!

Answer : scripted uninstalls

Hi zequestioner,

I don't know what your reg query is looking for, but "App .2" is not a normal reg value written when a windows installer application is installed, but 'DisplayName' is pretty-much always written, as per my first post at ID:33062098.

And t0t0 is correct about the reg.exe return code - 0 (zero) = success or in this case, it exists.

There was also a quote missing from the of the registry key in the reg.exe query.

Try the below as a direct replacement for your lines above in ID:33067935.  I have replaced /qn for /qb so that you can see msiexec.exe working for testing.

Hope this helps.
Daz.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Set PRODUCT_CODE={5FB7E3F6-F079-46F4-871F-C6ATB6AE7CE8}
Set REG_KEY="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%PRODUCT_CODE%"

reg query %REG_KEY% /v DisplayName > nul 2>&1

If %ERRORLEVEL% == 0 (
    %windir%\system32\msiexec.exe /x %PRODUCT_CODE% /qb
    Echo Uninstall called for app with product code: %PRODUCT_CODE%
) ELSE (
    Echo App with Product code %PRODUCT_CODE% is NOT INSTALLED
)
Random Solutions  
 
programming4us programming4us