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,5.0` MyDialogCaption=`Program uninstall` MyDialogX=10 MyDialogY=25 MyDialogWidth=304 MyDialogHeight=196 MyDialogNumControls=4 MyDialog01=`72,40,172,95,ITEMBOX,list,DEFAULT` MyDialog02=`118,24,52,DEFAULT,STATICTEXT,DEFAULT,"Program Remover"` MyDialog03=`112,161,51,DEFAULT,PUSHBUTTON,DEFAULT,"Delete",2` MyDialog04=`208,161,51,DEFAULT,PUSHBUTTON,DEFAULT,"Cancel",0` 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: W14462Filename: Add Remove Programs Example.txt