简体   繁体   English

C#应用程序在启动时未运行

[英]C# application not running on startup

I can't for the life of me figure this one out. 我无法为自己的生命弄清楚这一点。 I have created a fairly large C# application that basically runs a bunch of separate components and reboots the machine periodically. 我创建了一个相当大的C#应用​​程序,该应用程序基本上运行一堆单独的组件并定期重新启动计算机。 The idea of this application is basically to automate a process that we have at my company. 该应用程序的想法基本上是使我们公司拥有的流程自动化。 So I had it working previously so that after the machine reboots it launches after an account is logged into. 因此,我之前使它工作了,以便在计算机重新启动后,在登录帐户后启动。

Anyways the app no longer will launch on startup. 无论如何,该应用将不再在启动时启动。 Please see the code below which I have implemented to add an entry to the Run key in the registry: 请查看下面的代码,该代码已实现,用于向注册表中的“运行”项添加条目:

RegistryKey winStartUpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                string shieldStartVal = (string)winStartUpKey.GetValue("SHIELDCustomizer");
                if (shieldStartVal == null)
                {
                    string currentName = System.AppDomain.CurrentDomain.FriendlyName;
                    string currentDIR = Directory.GetCurrentDirectory() + @"\" + currentName;
                    RegistryKey startUpKey = Registry.LocalMachine.OpenSubKey
                        (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", RegistryKeyPermissionCheck.ReadWriteSubTree);
                    startUpKey.SetValue("SHIELDCustomizer", "\"" + currentDIR + "\"", RegistryValueKind.String);
                }

The above code has worked in the past. 上面的代码在过去一直有效。 And I have verified that the startup entry is in-fact added to the registry. 并且我已经验证了启动项实际上已添加到注册表中。 When I copy the path in the registry into a run prompt and click OK, the app starts without an issue. 当我将注册表中的路径复制到运行提示并单击“确定”时,该应用程序启动没有问题。

I have made some small changes to the code (rather lengthy code, not sure where to begin posting this code) that I can't imagine having an impact on whether or not the app launches on startup. 我对代码做了一些小的更改(相当长的代码,不确定从何处开始发布此代码),我无法想象会对应用程序是否在启动时启动产生影响。 All of my images and files have been added as a resource to the project. 我所有的图像和文件都已作为资源添加到项目中。 The only reference I could really find that outlined this similar scenario is on this forum here: application won't start on startup after adding a notifyicon which actually doesn't look like it pertains to my current setup because my notifyIcon object and properties have been added using Visual Studio and I have not coded it manually. 我能真正找到概述此类似情况的唯一参考资料是在此论坛上: 在添加一个notifyicon之后,应用程序将不会在启动时启动,它实际上看起来并不适合于我当前的设置,因为我的notifyIcon对象和属性已经是使用Visual Studio添加的,我尚未对其进行手动编码。

Does anyone have any idea as to what might be causing a program to not launch at startup when the correct entry is in the registry? 是否有人对注册表中正确的条目导致启动程序无法启动的原因有任何想法? I know I haven't provided much code, please let me know if there is any additional information I can provide and I will be happy to do so. 我知道我没有提供太多代码,请让我知道我是否可以提供其他信息,我将很乐意提供。

Thank you so much in advance! 提前非常感谢您!

Startup Tasks can be disabled using Task Manager in Windows 8.1 or msconfig in Windows 7. For example, I have disabled Box Sync from running at startup on my machine: 可以使用Windows 8.1中的任务管理器或Windows 7中的msconfig禁用启动任务。例如,我已禁用Box Sync在计算机上启动时运行:

在此处输入图片说明

Enabling/Disabling though task manager sets a registry key at 通过任务管理器在以下位置启用/禁用注册表项

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run

or 要么

HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run

If the value starts with 02 00 00 then it is enabled. 如果该值以02 00 00开头,则将其启用。 If it starts with another value (like 03 00 in my example) then it is disabled: 如果它以另一个值开头(例如本例中的03 00 ),则将其禁用:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM