設定UWP程式自啟動(Automate launching Windows 10 UWP apps)

來源:互聯網
上載者:User

標籤:導航   www   樣本   win   開啟   開發   --   cmd命令   服務   

原文:設定UWP程式自啟動(Automate launching Windows 10 UWP apps)

在開發UWP程式的過程中,有時候需要設定程式的自啟。本人實現的步驟如下:

1.在VS中啟用Protocol

 (Package.appxmanifest --> Declarations --> Add Protocol),圖示如下:


2.編譯並發布項目(Build and Deploy)

 發布之後Protocol被啟用,在(控制台 --> 程式 --> 預設程式 --> 設定關聯)中可以找到MYAPPLICATION的關聯。

3.命令列啟動UWP程式

 開啟命令列提示符,我們可以使用URI來啟動,樣本如下:

>start myapplication:                   //不帶參數>start myapplication:test-parameter     //帶參數

 輸入上述命令即可啟動應用。

4.程式中添加重寫方法

 在上述步驟完成後,雖然可以啟動UWP應用程式,但是程式中要重寫OnActivated方法來導航到需要顯示的頁面。

 在App.xaml.cs中重寫OnActivated方法。

protected override void OnActivated(IActivatedEventArgs args){    Frame rootFrame = Window.Current.Content as Frame;    if (rootFrame == null)    {        rootFrame = new Frame();        Window.Current.Content = rootFrame;    }    var protoclForResultsArgs = (ProtocolActivatedEventArgs)args;    rootFrame.Navigate(typeof(MainPage), protoclForResultsArgs);    Window.Current.Activate();          }

5.使用Windows服務在命令列啟動程式

 命令列實現URI程式啟動後,可以編寫Windows服務程式來監聽某些條件,從而啟動UWP程式。需要注意的點如下:

 (1).System.Diagnostics.Process可以實現程式中執行cmd命令;

 (2).Windows服務啟動UWP程式,需要在ProjectInstaller中設定serviceProcessInstaller的Account屬性為User,並指定相應的使用者;

 (3).如何建立Windows服務的連結:

  https://msdn.microsoft.com/zh-cn/library/zt39148a(v=vs.110).aspx#BK_CreateProject

設定UWP程式自啟動(Automate launching Windows 10 UWP apps)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.