'Using the UWP to open a runfulltrust desktop application breaks the desktop application
This really does not make any sense. I have a UWP application, titled FirstUWP. It opens fine on its own.
I have a desktop extension that I made called scrren.exe, taking advantage of tesseract to read some image from the screen. When first opening my UWP and then opening up the scrren.exe on it's own, both run fine.
However, when I use the runfulltrust launcher from UWP, the scrren.exe cannot write to a file that is under the UWP's project.
When they are launched entirely separately, the scrren.exe can write to the folder fine, it is just when the UWP launches it the scrren.exe cannot write to the folder within the UWP.
This code is the place where the problem occurs within the Desktop Extension sccren.exe. I've also attached a screenshot showing the Assets tree within the UWP, showing the Images folder which seems to be where my problems originate. Below that, I attached a screenshot showing what I mean that when launched from within UWP, scrren.exe shows up under the UWPs parent name, but this is where I get errors and scrren.exe cannot write to the Images folder.
I really hope this makes sense.
string result = Assembly.GetExecutingAssembly().Location;
int index = result.LastIndexOf("\\");
string rootPath = $"{result.Substring(0, index)}\\..\\";
using (Bitmap bitmap1 = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap1))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
try
{
using (bitmap1)
{
bitmap1.Save((rootPath + @"Scrn\Images\test.png"), System.Drawing.Imaging.ImageFormat.Png);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "Right here");
}
// Sleep for one second in order to let the file properly save
Thread.Sleep(1000);
}
Solution 1:[1]
You can't write to a packaged app's install location; it is read-only. Instead you should be using ApplicationData.Current.LocalFolder to get the local folder for saving files.
Also make sure you are using FullTrustProcessLauncher to launch your exe, not something like Process.Start().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peter Torr - MSFT |


