I inherited a UWP app and was asked to add a button to launch a 3rd party application. The 3rd party application is built with Qt and has an exe as the main program that launches a second exe that acts as a service. The UWP app is to be run on tablets running Windows 10.
I created an installer that adds registry values for the URI for the 3rd party application so I can do URI activation (LaunchUriAsync method). If I change the target of the URI to a different application it works fine, so I know the URI is setup properly.
When I hit the button the 3rd party application does not open. I used ProcMon to see what was happening and confirmed that it begins opening but then stops before launching the second exe. Nothing is written to the event log because that would be too helpful.
I haven't found any documentation about this, but I have to assume that an application launched from a UWP app is also sandboxed. Does anyone know if this is correct? I'm not sure what to do other than rebuild the app as WPF or something and that isn't very appealing.
The answer to your question is: no, that they are not being run sandboxed.
Launching an app that runs in fulltrust from a UWP via protocol is a supported scenario (e.g. that's how composing email works if Outlook is your default mailto: provider).
I suspect that is something missing in your protocol registration, or how you invoke it, but there is not enough detail in the question to troubleshoot this.
I was able to launch my 3rd party application by making a new console application for the UWP to launch that then starts a new process for it.
Console app is just this:
var proc = new Process();
proc.StartInfo.FileName = filePath;
proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath);
proc.Start();
proc.WaitForExit();
var exitCode = proc.ExitCode;
proc.Close();
The "WorkingDirectory" was required and from the UWP I don't see a way to set that.
Related
I'm working on creating custom Cortana commands. The commands are registered and executed using a Universal Windows Platform Application. (GitHub)
For instance, I've registered the following command
<Command Name="ShutDown">
<ListenFor>Shut down</ListenFor>
<Navigate/>
</Command>
To run this function in a UWP application
static async void ShutDown()
{
var dialog = new MessageDialog("This is where I would shut the computer down.");
await dialog.ShowAsync();
//System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
}
But after setting this up I learned System.Diagnostics.Process isn't supported in UWP.
The custom commands I want to run involve some sort of execution such as launching external programs, running other scripts, or opening websites.
It makes sense that UWP doesn't support them given that it's universal and an XBox or a phone might not be able to do these, but I was hoping there was some alternative or hacky way to accomplish this on a Windows 10 PC.
Is there a way for me to execute Process commands or something else with similar functionality in a UWP application? It seems like even though I can get Cortana to execute my C# code, UWP doesn't support much that would be useful in this situation.
Thanks in advance.
There are - limited - ways to achieve similar behavior.
You could use LaunchUri to trigger other apps which registered for a certain URI-Scheme. This should work for your webbrowser scenario. More details here:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.launcher.launchuriasync.aspx
You could trigger another app and get results back from it using LaunchForResults. The called app has to support this. More details here:
https://msdn.microsoft.com/en-us/library/windows/apps/mt269386.aspx
You could trigger App Services provided by another app. The called app has to support this. The app service will be executed in background. ( I think this is pretty cool.) More details here:http://blogs.msdn.com/b/mvpawardprogram/archive/2015/06/11/writing-windows-10-app-services-in-javascript.aspx
This is a little hacky: I'm not sure if this still works but it did work for Windows 8.1: You could create a so called "Brokered Component". This allows you to trigger everything from you app on you machine, but you won't be able to publish a brokered component into the store. This also allowed Process.Start() on Windows 8.1. It only worked for sideloaded apps. I'm not sure if it still works on Windows 10.
More info here: https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx
Summary:
Starting another app is pretty easy as long as the target app registered as app service or registered a protocol handler (Uri scheme).
Starting scripts or other *.exe is impossible if option 4 doesn't work any longer.
With the Windows 10 Anniversary Update (1607) there is an option to enable this scenario on PC. With this API in the Desktop Extension SDK you can launch a fulltrust process that runs at the full user privileges:
https://learn.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.FullTrustProcessLauncher
This way you can light it up on the platforms where it is supported, i.e. PCs running 1607 or above. And your app will still be universal:
if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
This official MSDN document describes how to share data between Universal Windows Platform (UWP) apps. But can we pass a string to an UWP app from a Windows Forms app and launch the UWP app from Windows Forms app? I did not find any document for this scenario. I'm using C# but the language does not matter in this scenario.
NOTE: In our case, it's a long string that contains data that Windows Forms app wants to pass to the UWP app that uses that data.
The easiest way to do this would be to use a custom URI scheme and then launch the app using that.
Registering and handling custom URIs is thoroughly described in the official UWP documentation, so I encourage you to follow that. In short, you first register a custom URI scheme in your Package.appxmanifest and then override the OnActivated in App.xaml.cs and check if the IActivatedEventArgs.Kind is ActivationKind.Protocol. Then you cast IActivatedEventArgs to ProtocolActivatedEventArgs and use its Uri property to access the launched URI.
On the Windows Forms side of things you then just have to launch the URI and that will cause the UWP app to launch / activate. You do so by starting a process with the URI:
var url = "myapp:?someparam=somevalue";
var psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.FileName = url;
Process.Start(psi);
You can use the URI to pass in any string values to the UWP app by virtue of using query string parameters in the URI. You can read those in the OnActivated method in UWP app.
Of course, this is not the only solution, as you can now also use UWP APIs in Windows Forms and so you could for example pass data between the two apps using App Services. If you however need just one-way communication, custom URI is the way to go.
Alternative method - App Execution Alias
Since build 16226 UWP supports App Execution Alias, which allows you to declare a system-wide app name that can be used to launch the app from the command-line from anywhere in the system. You can read more about it in this blogpost. This way, you could launch the app directly by its name and just pass the arguments as process args.
In addition to #Martin Zikmund's answer; this article explains how you can start the UWP app from the command line, which is basically doing the same as Process.Start but might be easier in scripting scenario's. Doesn't work on all devices though.
c:\> explorer.exe shell:appsFolder\put-your-PackageFamilyName-here!put-your-app-ID-here
The query string addendum should work as well.
Take special note on how to get the parameters if you didn't set them yourself:
Browse to the InstallLocation corresponded to the PackageFamilyName
13. Open the AppxManifest.xml
14. Look for "Executable=" for the app you want. (As some app package contains more than one app, such mail and calendar are under the same packetage)
15. On the same line, find the ID of the app
Example to open mail app:
#Eric mentions "an even better command line option for launching the mail app"
c:\> explorer outlookmail:
which works perfectly! (thanks #Eric)
Originally I provided this approach:
c:\> explorer.exe shell:appsFolder\microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail
And, another use full command list
I have created a project with process start in c# it's running in local visual studio build,when I hosting it in IIS it's not running but it's starting the processes and nothing is displaying I checked it in task manager.Code sample:
Process process = new Process();
process.StartInfo.FileName = "calc.exe";
process.StartInfo.UseShellExecute = false;
process.Start()process.WaitForExit();
And I have tried following solutions
IIS7 does not start my Exe file by Process Start
Foo.cmd won't output lines in process
System.Diagnostics.Process.Start not work from an IIS
nothing helped.If any one knows please help me
Try setting the value of the Load User profile to True for the ApplicationPool that you are using for your application.
You can just select the application pool and select advanced settings under advanced setting you can find this option.
This worked for me.
ApplicationPool Settings screen shot
EDIT : but as spender said it is not advisable to launch an EXE from your IIS server as this may open up some way for hackers to attack on your application.
I have searched a lot and finally I find a solution,It my be helpful to some one.
Solution :
Asp.net with IIS runs as a service application, which means that it runs under another Window Station and Desktop. However, in Windows, the default visible Window Station and Desktop is WinSta0\Default, which is where the Shell(explorer.exe) runs. So the .exe you created is displayed in an invisible desktop.
Actually, Window Station and Desktop is a good sandbox for GUI security, since Windows do not want the normal GUI application to communication other Services applications through Windows Message.
To display the GUI from a non-visible service application, you have to break the security sandbox of WinSta0\Default, which is a little complex.
However, if you want to create a visible process, it is really hard. Normally, the recommended solution is creating a second GUI application like Winform, and the Asp.net and Winform can communicates through .Net Remoting or other Inter process communication technologies. When the Asp.net wanted to create the visible notepad process, it can tell the Winform client through Net Remoting, then Winform will simply Proces.Start notepad.exe on behalf of Asp.net process.
.Net Remoting is the solution to solve this problem
(refer this link .NET Remoting with an easy example )
Download sample from Click Here
I am trying to start a console application from a .NET Windows Service. The service is running on a Windows 2008 server.
I use Process.Start to run the console application and it runs( I can see it in the task mgr), but I never get the process id back and the call to Process.Start just hangs.
If I run the same service from my Windows 7 machine the process runs and I get the process Id back no problem.
I am confused ..
I had exactly this same problem. For me the key was to set StartInfo.UseShellExecute = false;
Is it possible that the process you are spawning is attempting to prompt the window station for user input? In which case it could hang...
Which process are you starting? Is it part of the platform/OS (like cmd.exe) or something custom?
After a long time search for a solution for this, I found the wise stones for my problem.
I made a new WindowsForm based program, with same Process.Start command, and then the standard "Windows Warning Security" dialog box shows up, and thats why it dosent work.
After turn off "User Access Control" the Windows Service works correctly.
can we invoke exe of application(made in .net) on remote server using local machine.
we have full credentail on all machine to execute process.
how can we achive that ?its require to open GUI on remote machine.
we tried using WMI/.dat file invoke but all opens process on Task Manager & could not lunch GUI..
anyone have idea to accomplish same??
You can use psexec for this.
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
At one point in time, you could write a Windows Service, run it under the local system account, and allow it to interact with the desktop. However, this will only work on Windows XP. Vista (and I assume Windows 7) show the UAC prompt first, which is annoying and sometimes only shows up on the taskbar until it's clicked.
We got around this by writing a WinForms app that had no visibility on its own, but this app watches for a trigger. When the trigger occurs, the program then launches the appropriate exe.
For example, the trigger may specify to open up a web page on our intra net. The program uses the System.Diagnostics.Process.tart() to launch the web page in the default browser.
The trigger can be one of many things... The exe can poll a database, web service, etc. The exe can host a WCF host use remoting, or it could use a FileSystemWatcher.
The most complicated part of writing such an app is figuring out the appropriate trigger. Launching the app is trivial using the System.Diagnostics.Process.
For our situation, we set the program up to just launch when Windows starts, USG a registry setting.
Use PsExec tools
with -i switch
Like
psexec \\remotecomputer -u username -p password -i 2 "your exe loacation"