WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Installation Licensing Setup
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Add Remove Program Example

Keywords: 	 Add/Remove Programs

Question:

I have a sample winbatch from the webboard. It is running Isuninst and Uninst. When these programs are run a dialog displays asking to confirm delete. Can you tell me anything about the Isuninst and Ininst programs and their options?

Answer:

The theory is that all the uninstall information required is in the [UninstallString] data item in the registry. However that line must be broken up in to the EXE section and the PARAMETERS section to be launched with the WinBatch RUN or RUNWAIT function. With a little parsing, the UninstallString could be properly broken up.

Alternatively, the entire string could be shoved into a ShellExecute and I think that will take it as is.

Something like this should work. This example can uninstall anything...including WinBatch:


IntControl (49, 3, 1, 0, 0)
IntControl (33, 0, 0, 0, 0)
regkey=0
key=RegOpenkey(@RegMachine, "Software\Microsoft\Windows\CurrentVersion\Uninstall")
list=RegQueryKeys(key)

RegClosekey(key)

MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Program uninstall`
MyDialogX=010
MyDialogY=025
MyDialogWidth=304
MyDialogHeight=195
MyDialogNumControls=004
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`073,041,171,094,ITEMBOX,list,DEFAULT,DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`118,025,050,011,STATICTEXT,DEFAULT,"Program Remover",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`113,161,051,011,PUSHBUTTON,DEFAULT,"Delete",2,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`209,161,051,011,PUSHBUTTON,DEFAULT,"Cancel",0,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")


if buttonPushed == 1 then exit

;exit

;Define the key we are interested in
key="Software\Microsoft\Windows\CurrentVersion\Uninstall\%list%[UninstallString]"
if key == 0
   Message("Error", "No unistall string found, please remove %list% manually")
	exit
endif
question = AskYesNo ("Warning!" , "Are you sure to uninstall %list% ?")
If question == @NO Then Exit

;get the uninstall command
uninstallstring=RegQueryValue(@regmachine,key)

;find the ".exe" in there
ptr=StrIndexNC(uninstallstring,".exe",0,@fwdscan)
;find the first spave after the .exe
ptr=StrIndexNC(uninstallstring," ",ptr,@fwdscan)

exepart=StrSub(uninstallstring,1,ptr-1)
parampart=Strsub(uninstallstring,ptr+1,-1)

;remove "double quotes" - if any - from the exe part
exepart=StrReplace(exepart,'"','')

;This is just for debugging to see if the string gets built correctly
Pause(exepart,parampart)


;Run the desired uninstall program
Run(exepart,parampart)


Another example that uses the Reggie Extender.

;This example displays a list of application and their uninstall strings.
AddExtender("WWREG34I.DLL")
teststring="DisplayName"
topkey=@REGMACHINE      ; start at HKEY_LOCAL_MACHINE
topsub="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

looktype=0              ; look at REG_SZ string values
lookat=2|8              ; Value Names | Match wholestring only
dosubtree=@TRUE         ; recurse subtree contents
retall=rRegSearch(topkey,topsub,teststring,looktype,lookat,dosubtree)

count=ItemCount(retall,@tab)
applist = ""
For X = 1 to count
	 keystring = ItemExtract(x,retall,@tab)
	 type = RegEntryType(topkey,keystring)
	 app = RegQueryEx(topkey,keystring,"",type)
	 ;;get uninstall path too
	 ptr = StrIndex(keystring, "[", 0, @FWDSCAN)
		 If ptr !=0
		    keypath = StrCat(StrSub (keystring, 1, ptr-1),"[UninstallString]")
			 If RegExistValue(topkey,keypath)==1 
			   if regEntryType(topkey,keypath)==1
			     uninstallpath = RegQueryValue(topkey, keypath)
				Else
		        uninstallpath = "UNKNOWN"
		      Endif
			 Else
		      uninstallpath = "UNKNOWN"
		    Endif
		 Else
		    uninstallpath = "UNKNOWN"
		 Endif
	 
    ;Include uninstall path
	 Applist = Strcat(applist, @TAB, app, "|",uninstallpath)
Next
applist = strtrim(applist)
AskItemList("Reggie Found %count% Entries",applist,@tab,@sorted,@single)

Article ID:   W14462
Filename:   Add Remove Programs Example.txt
File Created: 2005:10:14:08:49:12
Last Updated: 2005:10:14:08:49:12