AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by JoeWinograd » 05 Jan 2021, 15:51

Hi Folks,

I'm looking for AHK code that retrieves the list of app packages (built-in apps) on the local computer (only W8.1 and W10), i.e., the equivalent of this PowerShell code:

Code: Select all

Get-AppxProvisionedPackage -Online
I need only the DisplayName and PackageName, i.e., the equivalent of this PowerShell code (but happy to parse it myself regardless of the format in which it is retrieved):

Code: Select all

Get-AppxProvisionedPackage -Online | Format-Table DisplayName,PackageName
Sample output from that:

Code: Select all

Microsoft.Microsoft3DViewer            Microsoft.Microsoft3DViewer_2020.2010.15012.0_neutral_~_8wekyb3d8bbwe
Microsoft.MicrosoftSolitaireCollection Microsoft.MicrosoftSolitaireCollection_4.7.10142.0_neutral_~_8wekyb3d8bbwe
Microsoft.MicrosoftStickyNotes         Microsoft.MicrosoftStickyNotes_3.8.7.0_neutral_~_8wekyb3d8bbwe
Microsoft.MSPaint                      Microsoft.MSPaint_2020.2009.30067.0_neutral_~_8wekyb3d8bbwe
Microsoft.Office.OneNote               Microsoft.Office.OneNote_16001.13328.20478.0_neutral_~_8wekyb3d8bbwe
Microsoft.Print3D                      Microsoft.Print3D_3.3.791.0_neutral_~_8wekyb3d8bbwe
Microsoft.SkypeApp                     Microsoft.SkypeApp_15.67.97.0_neutral_~_kzf8qxf38zg5c
Microsoft.Windows.Photos               Microsoft.Windows.Photos_2020.20110.11001.0_neutral_~_8wekyb3d8bbwe
Microsoft.WindowsCalculator            Microsoft.WindowsCalculator_2020.2011.16.0_neutral_~_8wekyb3d8bbwe
Microsoft.WindowsCamera                Microsoft.WindowsCamera_2020.902.20.0_neutral_~_8wekyb3d8bbwe
Microsoft.WindowsSoundRecorder         Microsoft.WindowsSoundRecorder_2021.2010.8.0_neutral_~_8wekyb3d8bbwe
Microsoft.YourPhone                    Microsoft.YourPhone_2020.1210.719.0_neutral_~_8wekyb3d8bbwe
I know that I can run PowerShell in an AHK script, but I'm looking for pure AHK code (I'm fine with using DllCall). Thanks much, Joe


BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by BoBo » 05 Jan 2021, 17:24

The PowerShell stuff worked fine for me. So this is just for the records. And yes, the StrSplit() part [c|s]hould be RegExed instead.

Code: Select all

i:=0 , clipboard:=""
Run % "powershell -Command Get-AppxPackage	
	| where-object {$_.IsFramework -eq $false -And $_.SignatureKind -eq \""Store\""}						;	extract line where 'SignatureKind : Store' 
	| Format-List -Property PackageFamilyName, InstallLocation, PackageFullName								;	,InstallLocation,Name,Publisher,Architecture,ResourceId,Version,PackageFullName,IsFramework,PackageFamilyName,PublisherId,IsResourcePackage,IsBundle,IsDevelopmentMode,NonRemovable,Dependencies,IsPartiallyStaged,SignatureKind,Status
	| clip",, Hide																							;	copy to clipboard
;	| Out-File -FilePath C:\_MyPrograms\_Apps.txt"															;	write to file instead
ClipWait
Loop, Parse,% clipboard, `r
if InStr(A_LoopField,"PackageFullName") {																	; ie 'PackageFullName : Microsoft.Windows.Photos_8wekyb3d8bbw'
	FileRead, content, % "C:\Program Files\WindowsApps\" StrSplit(A_LoopField," : ").2 "\appxManifest.xml"	; check file
	app := InStr(content,"Id=""App""")	? "Explorer shell:appsFolder\"										; .. if appxManifest.xml contains Id="App" create UWP path
										. StrSplit(StrSplit(A_LoopField," : ").2, "_").1 					; extract & set 'Microsoft.Windows.Photos'
										. "_" 
										. StrSplit(StrSplit(A_LoopField," : ").2, "_").5 					; extract & set '8wekyb3d8bbw'
										. "!App`n" 
										: ""
	RunWait % app																								; Run 'Explorer shell:appsFolder\Microsoft.Windows.Photos_8wekyb3d8bbwe!App'
	}
Btw, this script will open all UWP's that it identifies. So you better rewrite the Loop section. HTH & good luck

teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by teadrinker » 05 Jan 2021, 17:43

You can run as admin this code:

Code: Select all

MsgBox, % Clipboard := CmdRet("powershell Get-AppxProvisionedPackage -Online | Format-Table DisplayName,PackageName")

CmdRet(sCmd, callBackFuncObj := "", encoding := "")
{
   static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
        , STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
        
   (encoding = "" && encoding := "cp" . DllCall("GetOEMCP", "UInt"))
   DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
   DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
   
   VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
   NumPut(siSize              , STARTUPINFO)
   NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
   
   VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)

   if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
                              , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
   {
      DllCall("CloseHandle", "Ptr", hPipeRead)
      DllCall("CloseHandle", "Ptr", hPipeWrite)
      throw "CreateProcess is failed"
   }
   DllCall("CloseHandle", "Ptr", hPipeWrite)
   VarSetCapacity(sTemp, 4096), nSize := 0
   while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
      sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
      ( callBackFuncObj && callBackFuncObj.Call(stdOut) )
   }
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
   DllCall("CloseHandle", "Ptr", hPipeRead)
   Return sOutput
}

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by JoeWinograd » 05 Jan 2021, 18:26

mikeyww wrote:Does this help?
Hi mikey,
Yes, very helpful! It gets most of what the PowerShell code gets, although not everything. But for my current purposes, it will do nicely. Much appreciated!
BoBo wrote:PowerShell stuff worked fine for me
Hi BoBo,
I've had no problem running PowerShell code in an AutoHotkey script, but my goal with this question is to do it without using PowerShell. But thanks for your response.
teadrinker wrote:You can run as admin this code
Hi teadrinker,
Tested here in W10...works perfectly! Thanks! However, if I'm understanding correctly the params to the CmdRet function, it is running the PowerShell code...right? If so, I'm looking for a solution that doesn't use PowerShell.

Regards, Joe

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by BoBo » 05 Jan 2021, 19:57

@Joe Winograd I don't understand why powershell'ing is a problem? It's the modern equivalent to cmd.exe's command set and fully embedded into Win8/10.
teadrinker's Dll-orgy handles all its stuff using plain AHK so the PS command bit is only a parameter within the function call. :shifty:
Last edited by BoBo on 05 Jan 2021, 21:33, edited 1 time in total.
Reason: Edit: "mentioning" Joe Winograd instead of Joe Glines.

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by JoeWinograd » 05 Jan 2021, 20:55

BoBo wrote:Joe Glines
I'm Joe Winograd.
BoBo wrote:don't understand why powershell'ing is a problem
It may or may not ultimately be a "problem", but for right now I'm investigating solutions that do not require PowerShell.
BoBo wrote::shifty:
Yes, very clever! But a "problem" is that it has to run elevated.

User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: AHK code to retrieve list of app packages (W8.1 and W10) without using PowerShell

Post by Joe Glines » 15 Jan 2021, 12:19

There's just too many Joe's in AutoHotkey... LOL
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!

Post Reply

Return to “Ask for Help (v1)”