B4J Question Using powershell with admin rights

danielbal

New Member
Dear B4J experts,
I'm new to B4J and with programming so pls be patient with me :)

I would like to use jShell with powershell to list all windows (10) default installed apps packages.
I need to capture the ouput of the following powershell command:

Get -AppxPackage -AllUsers | Where-Object {$._PackageUserInformation -ilike "*Installed*"} select
-Property Name

Log of the StdOut from the shell processCompleted procedure is empty (running other poweshell command such as "ls" do provides output, and I think the issue is that this command needs Administrator rights.

Is there a way to accomplish this? If yes, an example would be highly appreciated.

Thanks,
Danny.
 

danielbal

New Member
Appologize, the correct syntax for the powershell script is:
Get-AppxPackage -AllUsers | Where-Object {$_.PackageUserInformation -ilike "*Installed*"} | select -Property Name

Though the issue still the same.

Danny.
 
Upvote 0

NJDude

Expert
Licensed User
If you are running that from the command line you need to open the PowerShell console with admin rights otherwise you have to check and elevate the user on your script.

One more thing, the PackageUserInformation will be most certainly blank, so, to get all the packages you only need:
B4X:
Get-AppxPackage -AllUsers | Select-Object -Property Name

But, you can also use the code below, that will give you what you are looking for (if the PackageInfo is not blank):
B4X:
Get-AppxPackage -AllUsers | Select-Object Name, PackageUserInformation | Where-Object {$_.PackageUserInformation -like "*Installed"}
 
Last edited:
Upvote 0

danielbal

New Member
Thanks NJ.
My goal was to run a PS command with Jshell (not from windows command line or PS Admin console) and retrive its output to a string variable.
I was trying to avoid the need to request for username and password, but I guess it can't be done.

Danny.
 
Upvote 0

NJDude

Expert
Licensed User
Try this:

1- Save your code as a script (e.g. App.ps1 in C:\Temp for example).
2-Run the following command from JShell.
B4X:
C:\WINDOWS\system32\RunAs.exe /SaveCred /User:Administrator "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command & {C:\Temp\App.ps1}"
That will prompt you for the Administrator password only once (it will save the credentials).
 
Upvote 0
Top