C# 应用程序未在启动时运行 [英] C# application not running on startup

查看:54
本文介绍了C# 应用程序未在启动时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终其一生都无法弄清楚这一点.我创建了一个相当大的 C# 应用程序,它基本上运行一堆单独的组件并定期重新启动机器.这个应用程序的想法基本上是自动化我们公司的一个流程.所以我以前让它工作,所以在机器重新启动后,它会在登录帐户后启动.

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. 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.

无论如何,该应用程序将不再在启动时启动.请参阅下面的代码,我已实施该代码向注册表中的 Run 项添加条目:

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.

我对代码进行了一些小的更改(相当冗长的代码,不知道从哪里开始发布此代码),我无法想象这会对应用程序是否在启动时启动产生影响.我所有的图像和文件都已作为资源添加到项目中.我真正能找到的唯一参考资料是在这个论坛上概述了这种类似的情况:添加notifyicon 后,应用程序不会在启动时启动 这实际上看起来与我当前的设置不相关,因为我的notifyIcon 对象和属性是使用Visual Studio 添加的,而我还没有对其进行编码手动.

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.

当正确的条目在注册表中时,有没有人知道什么可能导致程序在启动时无法启动?我知道我没有提供太多代码,如果我可以提供任何其他信息,请告诉我,我很乐意提供.

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.

在此先感谢您!

推荐答案

可以使用 Windows 8.1 中的任务管理器或 Windows 7 中的 msconfig 禁用启动任务.例如,我已禁用 Box Sync 在我的机器上启动时运行:

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:

启用/禁用任务管理器将注册表项设置在

Enabling/Disabling though task manager sets a registry key at

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

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

如果值以 02 00 00 开头,则它被启用.如果它以另一个值开头(如我的示例中的 03 00),则它被禁用:

If the value starts with 02 00 00 then it is enabled. If it starts with another value (like 03 00 in my example) then it is disabled:

这篇关于C# 应用程序未在启动时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆