Service Msix Automatic Update

Copper Contributor

Hi,

 

We have a service that we deploy using msix, all is working, however we now need to have the service automatic updated wihtout user interaction. We deploy the service outside microsoft store and want it to be like that for now... Ive implemented a small command line utility that i run that will run 

 

[E:\WinUiPackage\TeklaTBone\TeklaTBoneMsix_1.2.43.0_Test] cmd /c powershell -command "Add-AppxPackage -ForceApplicationShutdown -Path E:\WinUiPackage\TeklaTBone\TeklaTBoneMsix_1.2.43.0_Test\TeklaTBoneMsix_1.2.43.0_AnyCPU.msixbundle"

 

when running this outside the service the utility works fine. However when i run under the service, and under SYSTEM account i get:

 

Install Msix E:\WinUiPackage\TeklaTBone\TeklaTBoneMsix_1.2.44.0_Test\TeklaTBoneMsix_1.2.44.0_AnyCPU.msixbundle
[C:\WINDOWS\system32] cmd /c powershell -command "Add-AppxPackage -ForceApplicationShutdown -Path E:\WinUiPackage\TeklaTBone\TeklaTBoneMsix_1.2.44.0_Test\TeklaTBoneMsix_1.2.44.0_AnyCPU.msixbundle"
Result: Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF9, Install failed. Please contact your software vendor.
(Exception from HRESULT: 0x80073CF9)
Deployment Add operation rejected on package 66daac85-c649-42b7-b4ee-0deca2697f95_1.2.44.0_neutral_~_63fv57jsaj22j
from: TeklaTBoneMsix_1.2.44.0_AnyCPU.msixbundle install request because the Local System account is not allowed to
perform this operation.
NOTE: For additional information, look for [ActivityId] 2a54b8ab-74ad-000d-8580-552aad74d801 in the Event Log or use
the command line Get-AppPackageLog -ActivityID 2a54b8ab-74ad-000d-8580-552aad74d801
At line:1 char:1
+ Add-AppxPackage -ForceApplicationShutdown -Path E:\WinUiPackage\Tekla ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (E:\WinUiPackage...yCPU.msixbundle:String) [Add-AppxPackage], IOException
+ FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

 

 

Its clear that the security for this account doesnt allow us to install the app. What are the alternatives here?

 

Ive tryed both runas, and elevate utilities... they both lock the process because they are requisting user interaction. either pass or uac bypass... Since we dont have the admin password this is not a possibility

 

Is there are any way of doing this wihtout the microsfot store?

 

Thanks

 

9 Replies

Have a look at AppInstaller files (https://docs.microsoft.com/en-us/windows/msix/app-installer/app-installer-file-overview). You can specify automatic update behaviour in the file itself, and when you want to push an update it's just a case of updating the appinstaller file to point to newer version(s) of your MSIX packages and it'll work its magic for you. You can continue to do the initial deployment with Add-AppxPackage (it supports appinstaller files), with subsequent updates managed by changes to the appinstaller file.

@JDHIntercede Thanks for the reply, this seems to be a way forward. however im running into problems running my app using the appinstaller....

 

If i install it from the bundle file, the service runs correctly.

If i install from the appinstaller while having the URI pointing to local folder or azure, the installation happens however it service doesnt run. I get this error:

 

Exception Info: Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)

 

This tells me the permissions after installing have somehow changed comparing to previous install method. Everything is installed, however this fails

optionsBuilder.UseSqlite($"Filename={Path.Combine(runningPath, "MyDatabase.db")}");

 

Also if i unistall the app, installed with appinstaller, then it unistalls but the service is still show in services control panel... Only after restarting the machine it disappears.

 

Thank you again

 

 

 

 

Hmm, I've not installed a service with AppInstaller myself but it should be identical to installing from the msixbundle directly. The only thing I can think is that services need admin permissions to install, and perhaps that's not happening when you use the AppInstaller. Does it ask you to elevate when you run it? If not, try running it from Add-AppxPackage in an elevated console and see if that sorts it - if it does, then it sounds like you've found a deficiency in the way AppInstaller handles admin installs.
Also the suggestion doesnt seem to work, or i am ensure how to test it:
<UpdateSettings>
<OnLaunch HoursBetweenUpdateChecks="24" />
<AutomaticBackgroundTask />
</UpdateSettings>

I have this, and i was expecting that by stoping the service and starting it again it would trigger the upgrade? Or the only real time this kicks in is if we restart the windows machine? Since this is a Windows Service?

@JDHIntercede restarting the machine also doesnt seem to make any updates happen... i can download the updated app installer and if i download it and run it asks to update so it looks ok from the appinstaller side... Is this not working because this msix app is a windows service?

The config you have here means that it will only check for updates on launch once in a 24hr period, and if it has just been installed then I suspect it's not going to look until 24hrs after that (although that's just a guess). Try removing the HoursBetweenUpdateChecks to enforce a check on every launch. It's also worth checking the features you're trying to use are supported on your version of Windows.

All this being said, if the permissions issue you mention earlier is because AppInstaller isn't elevating correctly then you may run into the same issue when it installs an update.

@JDHIntercede 

@JDHIntercede the appinstaller brings a request for admin, and i can see the service running under SYSTEM account so it should have the correct execution permissions. Ive removed the HoursBetweenUpdateChecks but still the same result... I think this is really what is expected from this scenario, but would be good to confirm...

Windows Services are really something that existed earlier to msix, recently they have introduce service deployment over msix but that im pretty sure simply runs a few sc create commands... Checking for updates is something that doesnt exist on launch windows service as for example running apps from msix, my service starts an exe and that exe definitely doesn't have logic to check for updates. Would be nice to confirm, in fact would be nice to confirm if this is at all supported by msix system since system services are quite new. My box should support it, its fairly recent 21H2 (added in 20H1)

Regarding the appinstaller permissions errors, i can only think of a bug with the appinstaller or a bug with msxbundle since they definitely have different behaviours.

 

ive made a sample in attachment

applicationdbcontext.cs should blow up when trying to create a db file in running path

optionsBuilder.UseSqlite($"Filename={Path.Combine(runningPath, "MyDatabase.db")}");

 

with msibundle it should work... 

 

once it installs, then you will notice the service doesnt boot and in event log you will see the error im talking about. 

 

thanks again for the help

 

It sounds like this might need escalating to Microsoft - unfortunately this is a community forum and I am not a Microsoft employee, so I don't really have the information you're looking for. It does sound to me like this isn't working as advertised though, but whether that's a bug or by design is not something I could answer. Sorry!

Hi @jocs,

 

Can you try this command instead of Add-AppxPackage

Add-AppxProvisionedPackage -Online -PackagePath ".\Test.msix" -SkipLicense