UWP / Desktop-Bridge communication using (Packaged) COM - c#

I'm currently developing a UWP application that now needs access to APIs that are normally not accessible by apps in an AppContainer.
As I'm not (yet) able to migrate to WinUI3, I want to try using DesktopBridge to do the otherwise restricted work.
As both processes have to communicate with each other, I thought of COM as it should make things relatively seamless once everything has been set up.
According to this page this should be possible using "Packaged Com".
I now have...
An Out-of-Process Com Server (c# net5.0) that is accessible by non-packaged win32 apps (e.g., PowerShell) but not my own UWP App.
The UWP App with the main logic and UI.
A Packaging Project, which creates a package out of both projects.
(Manifest)
The code is on GitHub: Repo.
Does someone have an idea how to solve this problem or got an alternative for IPC?
PS: Tutorials I used
Packaged Com
Out-Of-Proc COM in c#
Packaging / DesktopBridge

So if I understand you correctly, you want to communicate between a UWP app and a Win32 app, and these two apps are packaged inside a Windows Application Package Project. Please let me know if it is not correct.
For your scenario, since the two apps are packaged together with desktop bridge, I'd suggest you use the App Service. App service could be used not only between UWP apps but also between the UWP app and desktop app.
These are the detailed steps:
You need to declare the AppService connection in the Manifest file of the package project.
You need to call the App service API in the win32 application.
You need to handle the connection in the App.xaml.cs in the UWP app
You could check the detailed code and sample from Stefan Wick's blog - UWP with Desktop Extension – Part 3.

Related

UWP sending message to Windows Service using NamedPipes

I'm trying to create a UWP app for our tools, one of its functionality is to manage tfs outside visual studio using tf.exe console commands and other things, i noticed that UWP is sandboxed and only has limited access outside its deployment folder so im planning to use a windows service to be the one who will be doing all the heavy work and using NamedPipes to communicate between UWP and Windows Service, been searching a bit already but until now im still not able to establish connection between this 2 app
I'm using console as a sample and starting it from UWP using FullTrustProcessLuncher
I uploaded a sample project in github
https://github.com/vgdagpin/UWP2WindowsService
Any help would be appreciated
I don't know much about named pipes so I can't tell if that is correct. But generally, UWP apps use APP services to communicate with desktop apps because the app service is native UWP.
I'd suggest you take a look at #Stefan Wick's Blog - UWP with Desktop Extension Part 1,2,3. You could search for them in your browser. These tutorials show the way how to package desktop apps with UWP apps using Windows Application Packaging Project and how to establish communication between the UWP app and the console app using App service which should be what exactly you want. After you launched the console app from the UWP app, you could let the console app call the windows service to do what you need.

Access denied error for Process.Start inside .NET Standard library referenced in UWP

In my VS2017 solution, I created a UWP and .NET Standard Library 2.0.3 projects. Referenced Library project from UWP. Library project is using a System.Diagnostics.Process to start a process. In debug mode, I get access denied error at line Process.Start(...) of the code inside Library project.
I thought the purpose of new .NET Standard Library project was to support various platforms (.NET, .NET Core, UWP etc) uniformly. But I guess, the sandbox nature of UWP apps is probably not allowing me to run Process.Start(...) albeit the process is running inside Library project. Question: What I may be missing and/or how can we resolve the above issue?
You cannot launch process directly from UWP, but there are some alternative ways to do that. The first one is using FullTrustProcessLauncher, if you need some example, check this post series. Another way is using a WPF or WinForms application to host UWP Controls with the Xaml Islands where there aren't restrictions to call any .NET APIs, but remember, through this way, your app will work only on Desktop devices.
According to this answer, you can't use Process.Start in a UWP app. There are some alternatives for launching other apps, but you can't execute arbitrary .exe or other processes.

How to distribute a DeskBand via the Windows Store

I have a Deskband DLL written in C++ that is registered via calling regsvr32 mydeskband.dll. The Deskband has a configuration app written in C#, that I can likely convert to a UWP app using the desktop app converter. As far as I know, there isn't a way to distribute DLL that requires registration via the Windows store.
My question is, what is the best way for me to distribute this entire package via the Windows Store? My thought is I might only distribute the configuration app via the Windows store and have the app link to an online download of the exe file for installing the Deskband DLL, but this is cumbersome and messy. Is there a better way?
The Desktop App Converter and Windows 10 Creator's edition now supports out-of-proc COM servers. See here.
Registration is done in the AppxManfest.xml file. Not all scenarios are supported, but its worth a try to see if this will work for you.
If so, you'll be able to distribute your extension through the Windows Store.

Get Installed win32 application

Is there any way to get installed win32 applications in UWP project?(since in uwp project I am unable to add reference of wmi call and registry).If so how it is achieved ?
Classical win32 application can get installed win32 applications on the device by reading the registry. But in a store app, in short answer, it cannot. A store app runs in an isolated sandbox and cannot read the system level registry. For details reasons about why store app doesn't support access the registry please reference this thread.
However, if you don't want upload your app to windows store, you can try out the Brokered Windows Runtime Components for side-loaded Windows Store apps. Essentially, it allows you UWP app to call Win32 API hosted in a different process, which runs outside of the App container.
For brokered WinRT component template for VS2015 you can download here.
For more details and sample about Brokered Windows Runtime Components please reference this video and this document.
Is there any way to get installed uwp application in the system? I tried with PackageManager class bt it does not works.Is there some other way?.I dont want to use powershell.
For getting installed store apps, I have tested PackageManager class on my side. It did work well and as far as I know it is the best way to got installed store apps. Code as follows:
var packageManager = new PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser("");
var list = packages.ToList();
Pay attention that these code running on uwp require packageManagement restricted capability. More details about special and restricted capabilities this. And your app cannot be uploaded to windows store.
For using this code in traditional Win32 project just referernce the sample in this document.

How to execute a Console App by passing parameters to it from a Windows Universal App in Visual Studio?

I have a console app written in c# visual studio and a Windows Universal App. The Universal App has data streaming in, I want to pass that data to the console app which plots it. I have tried various way of doing it including the "Process" but my project isn't able to find that library. Any suggestion would be appreciated.
Thanks
UWP Apps are sandboxed, and can't launch external applications.
If the console app is already running, you may be able to communicate with it (by using sockets for instance). But there's no way to launch it (unless it's another UWP app). That's for security reasons, thank to this you can download any app from the store and run them safely on your computer.

Categories

Resources