Registry Uninstall

Started by stanl, December 20, 2020, 07:21:01 AM

Previous topic - Next topic

stanl

I have an friend who has several clients and he wants to track their installed 32/64 bit apps. Simple Powershell script can give both if run in either 32/64 Powershell.  Anyway, he wanted to see it it WB.  I felt the script would start:
Code (WINBATCH) Select


paths ='@REGMACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'@REGMACHINE,SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'@REGCURRENT,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'@REGCURRENT,SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'





But WB Help says:

       
  • NEVER directly access keys stored under WOW6432node.
So, in order to replicate the Powershell and return values for :


DisplayName, DisplayVersion, UninstallString,  [when there]QuietUninstallString




would this entail moving between RegOpenFlags(64) and RegOpenFlags(32) and just remove Wow6432Mode?

td

Powershell isn't doing anything magical but I degress... Almost all WinBatch registry functions have an option "view" parameter.  By default both WinBatch registry functions are set to the 64-bit view of the registry.  The 64-bit view is the view that does not have "Wow6432Node" in its path. So when you want to access a path with "Wow6432Node" in its path you just set the "view" parameter to the value 32. So you don't need even use the  "RegOpenFlags" function.

This topic is also covered in the Consolidated WIL Help file in the Registration Database section.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Well, Powershell isn't doing anything Magical but 1-2 lines of code works. Accepting the RFM rebuke, I did go over WB registry functions {which, to be honest, haven't used in years}...  I came up with a script [below] which doesn't fail, but doesn't find anything either... there is something wrong about putting together the final string to query values. I tried several options but still no success. Turning over to the gurus as it might make a good candidate for Tech DB


[EDIT]: actually think it worked ::)

Code (WINBATCH) Select


;Winbatch 2020A - PC Inventory from Registry
;Stan Littlefield December 23,2020
;feel free to improve....
;=============================================================================
IntControl(73,1,0,0,0)
gosub udfs
cFile = dirscript():"PCInv.csv"
cCSV= "DisplayName,DisplayVersion,UninstallString,Scope,Architecture":@CRLF
skeys="[DisplayName],[DisplayVersion],[UninstallString]"
paths ='AllUsers,64,@REGMACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'AllUsers,32,@REGMACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'CurrentUser,64,@REGCURRENT,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'CurrentUser,32,@REGCURRENT,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'
n=ItemCount(paths,@TAB)
BoxOpen("Please Wait","Itemizing Installed Apps...")
For i=1 to n
   entry = ItemExtract(i,paths,@TAB)
   scope = ItemExtract(1,entry,",")
   x3264 = Int(ItemExtract(2,entry,","))
   creg = ItemExtract(3,entry,",")
   reg = @REGMACHINE
   If creg == "@REGCURRENT" Then reg = @REGCURRENT
   top = ItemExtract(4,entry,",")
   cnt=0
   key=0
   key=RegOpenKey(reg,top,x3264)
   subkeys = RegQueryKeys(key)
   cnt=ItemCount(subkeys,@TAB)
   If cnt>0
      For x=1 to cnt
          getApps()
      Next
   Endif
   RegCloseKey(key)


Next


FilePut(cFile,cCSV)
BoxShut()


Exit
;======================================================================================================
:WBERRORHANDLER
Terminate(@TRUE,"Error Encountered",err())
;======================================================================================================
:udfs
#DefineSubRoutine err()
If key<>0 Then RegCloseKey(key)
wberroradditionalinfo = wberrorarray[6]
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
Return(errmsg)
#EndSubRoutine


#DefineSubRoutine getApps()
IntControl(73,1,0,0,0)
tmpVal=""
For j=1 to 3
   skey=ItemExtract(x,subkeys,@Tab)
   name= skey:ItemExtract(j,skeys,",")
   ;name= top:skey:"\":ItemExtract(j,skeys,",")
   BoxText(name)
   If RegExistValue(key,name)
      type = RegEntryType(key,name,x3264)
      If type == 0
         nameVal= "Not Found"
      Else
         ;nameVal=RegQueryValue(key,name,x3264)
         nameVal=RegQueryEx(key,name,"|",type,x3264)
      Endif
   Else
      nameVal= "Not Found"
   Endif
   tmpVal = tmpVal:nameVal:","
Next
tmpVal = tmpval:scope:",":x3264:@CRLF
cCSV = cCSV:tmpVal


Return(1)
;======================================================================================================
:WBERRORHANDLER
Message("",cCSV)
Terminate(@TRUE,"Error Encountered",err())
;======================================================================================================


#EndSubRoutine


Return
;======================================================================================================



stanl

Below is what I compiled for my friend. Added a choice dialog with an option to create Excel. I think it works, but did notice a few issues with Microsoft Edge which on my laptop installed as both 64/32. Thought about adding the Install Date, or making the Uninstall a hyperlink in the Excel column. But I have a better understanding of WB registry functions and it was fun. And Happy Holidays for all who read this and make this forum the best.
Code (WINBATCH) Select


;Winbatch 2020A - PC Inventory from Registry
;Stan Littlefield December 23,2020
;feel free to improve....
;=============================================================================
IntControl(73,1,0,0,0)
gosub udfs
cFile = dirscript():"PCInv.txt"
If FileExist(cFile) Then FileDelete(cFile)
cCSV = "DisplayName,DisplayVersion,UninstallString,Scope,Architecture":@CRLF
cCSV = StrReplace(cCSV,",",@TAB)
skeys ="[DisplayName],[DisplayVersion],[UninstallString]"
paths ='AllUsers,64,@REGMACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'AllUsers,32,@REGMACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'CurrentUser,64,@REGCURRENT,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\':@TAB
paths = paths:'CurrentUser,32,@REGCURRENT,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'
n=ItemCount(paths,@TAB)


MyDialogFormat=`WWWDLGED,6.2`


MyDialogCaption=`64 and 32 bit installed Applications`
MyDialogX=107
MyDialogY=127
MyDialogWidth=178
MyDialogHeight=064
MyDialogNumControls=004
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0


MyDialog001=`011,033,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,"128|255|0"`
MyDialog002=`119,033,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,"255|0|0"`
MyDialog003=`011,011,064,012,RADIOBUTTON,"RadioButton_1",nChoice,"Create Text File Only",1,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`083,011,084,012,RADIOBUTTON,"RadioButton_2",nChoice,"Create File and Place in Excel",2,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`


ButtonPushed=Dialog("MyDialog")




BoxOpen("Creating Application Inventory...Please Wait","Itemizing Installed Apps...")
For i=1 to n
   entry = ItemExtract(i,paths,@TAB)
   scope = ItemExtract(1,entry,",")
   x3264 = Int(ItemExtract(2,entry,","))
   creg = ItemExtract(3,entry,",")
   reg = @REGMACHINE
   If creg == "@REGCURRENT" Then reg = @REGCURRENT
   top = ItemExtract(4,entry,",")
   cnt=0
   key=0
   key=RegOpenKey(reg,top,x3264)
   subkeys = RegQueryKeys(key)
   cnt=ItemCount(subkeys,@TAB)
   If cnt>0
      For x=1 to cnt
          getApps()
      Next
   Endif
   RegCloseKey(key)


Next


FilePut(cFile,cCSV)


If nChoice==2
   BoxText("Placing ":cFile:" into Excel")
   toXLSX()
   Exit
Else
   BoxText(cFile:" created")
   TimeDelay(2)
   BoxShut()
Endif
Exit
;======================================================================================================
:WBERRORHANDLER
Terminate(@TRUE,"Error Encountered",err())


:CANCEL
Display(2,"Program Canceled","Goodbye...")
Exit
;======================================================================================================
:udfs
#DefineSubRoutine err()
If key<>0 Then RegCloseKey(key)
wberroradditionalinfo = wberrorarray[6]
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
Return(errmsg)
#EndSubRoutine


#DefineSubRoutine getApps()
IntControl(73,1,0,0,0)
tmpVal=""
For j=1 to 3
   skey=ItemExtract(x,subkeys,@Tab)
   name= skey:ItemExtract(j,skeys,",")
   ;name= top:skey:"\":ItemExtract(j,skeys,",")
   BoxText(name)
   nameVal = " "
   If RegExistValue(key,name)
      type = RegEntryType(key,name,x3264)
      If type == 0
         If j==1 Then nameVal= name:" [Not Found]"
      Else
         ;nameVal=RegQueryValue(key,name,x3264)
         nameVal=RegQueryEx(key,name,"|",type,x3264)
      Endif
   Else
      If j==1 Then nameVal= name:" [Not Found]"
   Endif
   tmpVal = tmpVal:nameVal:@TAB
Next
tmpVal = tmpval:scope:@TAB:x3264:@CRLF
cCSV = cCSV:tmpVal


Return(1)
;======================================================================================================
:WBERRORHANDLER
Message("",cCSV)
Terminate(@TRUE,"Error Encountered",err())
;======================================================================================================


#EndSubRoutine


#DefineSubRoutine toXLSX()
IntControl(73,1,0,0,0)
ClipPut(cCSV)
oXL = CreateObject("Excel.Application")
oXL.Visible          = @TRUE  ; change this to @FALSE to run hidden
oXL.ScreenUpdating   = @TRUE  ; if running hidden, change this to @FALSE
oXL.UserControl      = @TRUE
oXL.DisplayAlerts    = @FALSE
oXL.WorkBooks.Add()
BoxShut()
oWS = oXL.ActiveWorkBook.Worksheets(1)
oWS.Activate()
oWS.Name = "PC Inventory"
oWS.Cells(1,1).Select()
oWS.Paste()
oWS.UsedRange.Select()
oXL.Selection.Font.Name = 'Tahoma'
oXL.Selection.Font.Size = 9
oXL.Selection.Font.Bold = @True
oWS.UsedRange.Columns.Autofit()
oWS.ListObjects.Add(:1,oWS.UsedRange, , 1).Name ="Table1"
oWS.Range("Table1[#All]").Select()
oWS.ListObjects("Table1").TableStyle = "TableStyleLight15"
oXL.ActiveWindow.DisplayGridlines = @False
oWS.Cells(1,1).Select()
oWS=0
oXL=0
Pause("Data Loaded Into Excel","Save or Close Workbook")
Return(1)
;======================================================================================================
:WBERRORHANDLER
Terminate(@TRUE,"Error Encountered",err())
;======================================================================================================


:CANCEL
Display(2,"Thank you","Goodbye...")
Exit


#EndSubRoutine


Return
;======================================================================================================