3

I am designing a Windows 10 Universal application using this https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Printing/cs repository as a guide. I currently have fully functional printing by calling:

await Printmanager.ShowPrintUIAsync(); 

In my application there is also an activity timer that logs the user out after a certain amount of time inactive. This part is working fine, but I am unable to close the print ui upon logout.

Note: Normally to close a windows async operations, you can do something similar to:

IAsyncOperation<bool> printOperation = Printmanager.ShowPrintUIAsync();
printOperation.Cancel();

This works for other AsyncOperation occurences, but I cannot get it to work for the print UI, as the print UI is not a child process of the app, but is a seperate process itself

Thanks in advance!

Also, it seems there was a solution to kill processes in Windows 8 which is no longer supported in Windows 10 applications (Process.GetProcessByName .... or FindWindow)

Perhaps there is someway to kill a Windows 10 process by name?

gwcoderguy
  • 392
  • 1
  • 13
  • you could use FindWindow (winAPI) or Process.GetProcessesByName() then kill the process. – Sorceri Aug 06 '15 at 14:16
  • hmm, I'm unable to get either of those to be recognized by Visual Studio 2015 (with the header: using System; using System.Diagnostics; using System.ComponentModel; ) – gwcoderguy Aug 06 '15 at 14:41
  • System.Diagnostics.Process.GetProcessByName(String), https://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx and FindWindow is a C++ method so you will need to use DLLImport and supply the signature. Search SO for C# FindWindow – Sorceri Aug 06 '15 at 14:57
  • 2
    I could be wrong, but doesn't that only work for Windows Desktop Apps? – gwcoderguy Aug 06 '15 at 15:02
  • FindWindow will find any top level window on the desktop, correct. GetProcessByName should work with anything listed in the task manager. – Sorceri Aug 06 '15 at 15:20
  • 1
    In the GetProcessByName documentation it says: Windows 2000 Professional [desktop apps only], additionally the Systems.Diagnotics dll doesn't appear to be supported by Windows 10. Again, I could be wrong (and hope I am!). – gwcoderguy Aug 06 '15 at 15:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/85315/discussion-between-gwcoderguy-and-sorceri). – gwcoderguy Aug 06 '15 at 15:36
  • my bad, the link was to findwindow, here is the GetProcessByName link, https://msdn.microsoft.com/en-us/library/z3w4xdc9(v=vs.110).aspx – Sorceri Aug 06 '15 at 15:37
  • 2
    Are you sure you can use this in a Windows 10 Universal app, I'm unable to get the dll – gwcoderguy Aug 06 '15 at 16:02
  • 1
    FindWindow cannot be used in Windows Store Apps, this function is part of the GDI API, it is based on Windows handles which do not even exist for Windows Store/Universal/Phone/Metro/WinRT Apps.By the way the class System.Diagnostics.Process is also restricted. – yms Aug 07 '15 at 18:01
  • @gwcoderguy The print UI is a WinRT Charm, so this may help: http://stackoverflow.com/questions/17469978/how-can-i-close-charmbar-programmaticly-in-winrt – yms Aug 07 '15 at 18:07
  • Are you sure this is still supported in Windows 10? When I try this.Focus(); visual studio suggests generating a focus method. – gwcoderguy Aug 07 '15 at 18:30
  • 1
    I think [it is supported](https://msdn.microsoft.com/en-us/library/windows/apps/hh702161.aspx). Are you sure you are calling it from the right place? – yms Aug 07 '15 at 20:11
  • ah, you are correct. However, even upon a successful call (I check the return value) it neither diverts focus from the print UI nor closes it. – gwcoderguy Aug 11 '15 at 19:00

1 Answers1

1

You can't do that.

All the Metro-style applications work in the highly sandboxed environment and there is no way to directly start an external application. Taken from this article

maybe the solution is creating a proxy. How to Start a external Program from Metro App

This could help you, because you can kill the process indirectly.

I hope this helps.

RicardoPons
  • 1,323
  • 9
  • 14