C# 注册表自动启动导致错误“;基础提供程序在打开时失败";

C# 注册表自动启动导致错误“;基础提供程序在打开时失败";,c#,autostart,C#,Autostart,正在将程序添加到注册表: Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", true); key.SetValue("App", AppDomain.CurrentDomain.BaseDirectory + "App.exe"); key.Close(); Micro

正在将程序添加到注册表:

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

key.SetValue("App", AppDomain.CurrentDomain.BaseDirectory + "App.exe");
key.Close();
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

key.DeleteValue("App", false);
key.Close();
以及从注册表中删除:

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

key.SetValue("App", AppDomain.CurrentDomain.BaseDirectory + "App.exe");
key.Close();
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

key.DeleteValue("App", false);
key.Close();
启动程序后,如果我不注销并关闭程序,则需要登录或自动登录

因此,问题是:

  • 启动机器并启动程序后,会弹出一个错误,文本为“基础提供程序在打开时失败”

  • 当我填写授权表并单击“登录”时,一切正常

  • 可能是因为某些Windows服务(如SQL Server)的启动时间比我的程序或类似程序的启动时间晚


    我该怎么办?

    你自己的结论可能确实是准确的;这种情况下的解决方案是向应用程序添加代码,等待它所依赖的任何其他服务启动。请查看此搜索,以便开始: