WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on March 05, 2020, 03:47:27 AM

Title: Registry skills refresh
Post by: stanl on March 05, 2020, 03:47:27 AM
Noticed I hadn't worked with WB registry functions in a script since 2006. Below is something I put together with help from Consolidated Help to enumerate installed app paths.
Code (WINBATCH) Select


;Winbatch 2020A - Enumerate Installed Application Path
;testing for 64-bit / RegEntryType
;=========================================================================================
IntControl(73,1,0,0,0)
gosub udfs


RegOpenFlags(64)
key=RegOpenKey(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\")
list=RegQueryKeys(key)
RegCloseKey(key)
count = ItemCount( list, @TAB )


allapps=""


For x = 1 To count
   item=ItemExtract( x, list, @TAB )
   If RegExistValue(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]")
      type=RegEntryType(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]")
      delim=Num2Char(255)
      app=RegQueryEx(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]",delim,type)
      allapps=StrCat(allapps,@CRLF,app:item)
   EndIf
Next


Message("",allapps)
Exit


:udfs
#DefineSubRoutine geterror()
   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


Return
Title: Re: Registry skills refresh
Post by: td on March 06, 2020, 07:08:32 AM
Thanks.  Somehow I don't think you are the only one that needs to refamiliarize themselves with some of the more than 1000 WIL and extender functions from time to time.
Title: Re: Registry skills refresh
Post by: stanl on March 06, 2020, 02:44:39 PM
Quote from: td on March 06, 2020, 07:08:32 AM
Thanks.  Somehow I don't think you are the only one that needs to refamiliarize themselves with some of the more than 1000 WIL and extender functions from time to time.


Trying to expand the output to get FileVersionInfo.FileDescription using the CDL
Title: Re: Registry skills refresh
Post by: kdmoyers on March 07, 2020, 08:02:52 AM
Quote from: td on March 06, 2020, 07:08:32 AM
Thanks.  Somehow I don't think you are the only one that needs to refamiliarize themselves with some of the more than 1000 WIL and extender functions from time to time.
(innocently) What, me? (yeah ok me)
Title: Re: Registry skills refresh
Post by: stanl on March 07, 2020, 09:17:24 AM
So, I added a UDF to return the FileDescrption.  Seems like it errors a lot, but handled that with a Path Cannot be Evaluated Pontius Pilate clause.  The script currently only acts on installed exe's.... but could be expanded. I guess the question: Could i signify a file description for a Compiled WB script that could be picked up by System.Diagnostics
Code (WINBATCH) Select


;Winbatch 2020A - Enumerate Installed Application Path
;testing for 64-bit / RegEntryType
;=========================================================================================
IntControl(73,1,0,0,0)
gosub udfs


ObjectClrOption("useany", "System")
oVer = ObjectClrNew('System.Diagnostics.FileVersionInfo')


RegOpenFlags(64)
key=RegOpenKey(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\")
list=RegQueryKeys(key)
RegCloseKey(key)
count = ItemCount( list, @TAB )
allapps=""


For x = 1 To count
   item=ItemExtract( x, list, @TAB )
   If RegExistValue(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]")
      type=RegEntryType(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]")
      delim=Num2Char(255)
      app=RegQueryEx(@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%item%[Path]",delim,type)
      descrip = getdescrip(app:item)




      allapps=StrCat(allapps,@CRLF,app:item:@TAB:descrip)
   EndIf
Next


oVer =0
Message("",allapps)
Exit


:udfs
#DefineSubRoutine geterror()
   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 getdescrip(d)
IntControl(73,1,0,0,0)
vs = oVer.GetVersionInfo("%d%")
Return(vs.FileDescription)
:WBERRORHANDLER
IntControl(73,1,0,0,0)
Return("Path Cannot Be Evaluated")
#EndSubRoutine


Return
Title: Re: Registry skills refresh
Post by: td on March 09, 2020, 07:55:57 AM
Assuming I understand the question, you can set the "FileDescription" of a compiled script from the compiler's Version Dialog or by hand-editing the .cmp file.  That text should be picked up as the FileDescription property of the class.  You can also use the WIL FileVerInfo function to obtain the same info.

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_F__032.htm (https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_F__032.htm)
Title: Re: Registry skills refresh
Post by: stanl on March 10, 2020, 03:11:14 AM
Quote from: td on March 09, 2020, 07:55:57 AM
You can also use the WIL FileVerInfo function to obtain the same info.


Yep. Another lesson in re-familiarization :-\