Original: Set up UWP program self-boot (automate launching Windows UWP apps)
In the process of developing a UWP program, it is sometimes necessary to set the program's self-start. The steps I implemented are as follows:
1. Activating protocol in VS
(Package.appxmanifest---Declarations and Add Protocol), as shown below:
2. Compiling and publishing the project (Build and Deploy)
Protocol is activated after publishing, and the association of MyApplication can be found in (Control Panel------The default program---set association).
3. Command line launch UWP program
To open a command-line prompt, we can start with a URI, with the following example:
>start MyApplication: //without parameters >start Myapplication:test-parameter //with parameters
Enter the above command to launch the app.
4. Add an override method to the program
After the above steps are complete, you can start the UWP application, but you will override the Onactivated method in your program to navigate to the page you want to display.
Override the Onactivated method in App.xaml.cs.
protected override void OnActivated (Iactivatedeventargs args) {Frame rootframe
= Window.Current.Content as Frame; if (rootframe = = null " {Rootframe = new Fram E (); Window.Current.Content = Rootframe; var protoclforresultsargs = ( Protocolactivatedeventargs) args; Rootframe.navigate ( typeof (MainPage), Protoclforresultsargs); Window.Current.Activate (); }
5. Using Windows services to start a program at the command line
After the command-line implementation URI program starts, you can write a Windows service program to listen for certain conditions to start the UWP program. The points to note are as follows:
(1). System.Diagnostics.Process can implement the cmd command in the program;
(2). The Windows service launches the UWP program and needs to set the account property of ServiceProcessInstaller to user in ProjectInstaller and specify the appropriate users;
(3). How to create a link to a Windows service:
https://msdn.microsoft.com/zh-cn/library/zt39148a (v=vs.110). Aspx#bk_createproject
Set up UWP program self-boot (automate launching Windows ten UWP apps)