首页 技术 正文
技术 2022年11月14日
0 收藏 915 点赞 4,702 浏览 1043 个字

在开发UWP程序的过程中,有时候需要设置程序的自启。本人实现的步骤如下:

1.在VS中激活Protocol

 (Package.appxmanifest –> Declarations –> Add Protocol),图示如下:

设置UWP程序自启动(Automate launching Windows 10 UWP apps)
2.编译并发布项目(Build and Deploy)

 发布之后Protocol被激活,在(控制面板 –> 程序 –> 默认程序 –> 设置关联)中可以找到MYAPPLICATION的关联。

设置UWP程序自启动(Automate launching Windows 10 UWP apps)

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,157
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,625
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,469
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,241
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,878
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,044