【发布时间】:2019-01-26 17:17:50
【问题描述】:
我想用 Windows 启动我的 wpf 应用程序。但是当我像 uwp 应用程序一样安装它时它不起作用。
这是在运行时设置启动的代码:
static public void SetStartup()
{
DeleteStartup();
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue(Global.GlobalConstant.APPLICATIONNAME, Directory.GetCurrentDirectory().ToString() + @"\" + Global.GlobalConstant.APPLICATIONNAME);
}
static public void DeleteStartup()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
key.DeleteValue(Global.GlobalConstant.APPLICATIONNAME, false);
}
static public void SetStartLocation()
{
RegistryKey RegKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (RegKey.GetValue(GlobalConstant.APPLICATIONNAME) != null)
{
string Path = RegKey.GetValue(GlobalConstant.APPLICATIONNAME).ToString();
Path = Path.Remove(Path.Length - GlobalConstant.APPLICATIONNAME.Length, GlobalConstant.APPLICATIONNAME.Length); // Now it's a valid directory.
Directory.SetCurrentDirectory(Path);
}
}
但它不起作用,因为 uwp 应用程序会自行安装在特定文件夹中。 (C:\Program Files\WindowsApps)
有什么解决办法吗? 谢谢
【问题讨论】:
-
如果您想将 WPF 应用程序安装为“UWP 应用程序”,您应该使用desktop bridge。我不确定您要对注册表做什么。
-
这个 uwp 只在 pc 上可用,所以我想用 windows 启动我的应用程序。
标签: c# wpf windows uwp startup