C# 应用程序选择器在启动时显示,而不是运行我的应用程序

C# 应用程序选择器在启动时显示,而不是运行我的应用程序,c#,wpf,windows,startup,C#,Wpf,Windows,Startup,使用WPF创建基本windows应用程序后, 我将我的应用程序可执行文件添加到注册表中,因此它应该在打开电脑后启动 然而,在打开后,windows似乎打开了我的应用程序,但不知道如何打开(问我:“你想如何打开应用程序”,列表中有记事本浏览器等) 我还添加了webstorm exe作为测试,它在启动时打开 RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\

使用WPF创建基本windows应用程序后, 我将我的应用程序可执行文件添加到注册表中,因此它应该在打开电脑后启动

然而,在打开后,windows似乎打开了我的应用程序,但不知道如何打开(问我:“你想如何打开应用程序”,列表中有记事本浏览器等)

我还添加了webstorm exe作为测试,它在启动时打开

 RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

        try
        {
            reg.SetValue("My application", System.Reflection.Assembly.GetEntryAssembly().Location);
            reg.SetValue("Webstorm", "C:\\Program Files (x86)\\JetBrains\\WebStorm 2016.2\\bin\\WebStorm.exe");
        }
        catch (UnauthorizedAccessException)
        {
            MessageBox.Show("You dont have permission", "Exception", MessageBoxButton.OK, MessageBoxImage.Information);

        }
        catch (Exception e)
        {
            MessageBox.Show("Other Exception " + e.Message, "Other Exception", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        MessageBox.Show("Your app succesfilly registered", "Message", MessageBoxButton.OK, MessageBoxImage.Information);

不要只使用.Location,而是使用.exe将应用文件名添加到其中。

好的。。。。不知道为什么会这样

但改变这一行:

 reg.SetValue("My application", System.Reflection.Assembly.GetEntryAssembly().Location);
为此:

reg.SetValue("FirstApp","\""  + System.Reflection.Assembly.GetEntryAssembly().Location + "\"");
创造了魔法。。。
注册表中的输出看起来完全相同。。。但是它可以工作并打开我的应用程序。

我有点困惑,.location已经有了我的应用程序文件名.exe的完整路径,比如:…/bin/myApp.exe似乎在可执行文件的路径中有空格。添加双引号将解决此问题,否则windows无法正确识别路径