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

时间:2015-05-01 20:07:03

标签: c# windows startup

我不能为我的生活想出这个。我创建了一个相当大的C#应用​​程序,它基本上运行一堆独立的组件并定期重新启动机器。这个应用程序的想法基本上是自动化我们公司的流程。所以我以前让它工作,以便在机器重新启动后,它会在帐户登录后启动。

无论如何,应用程序不再会在启动时启动。请参阅下面的代码,我已经实现了在注册表中添加运行键的条目:

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);
                }

上述代码过去曾有效。我已经验证了启动条目实际上已添加到注册表中。当我将注册表中的路径复制到运行提示符并单击“确定”时,应用程序启动时没有问题。

我对代码进行了一些小的更改(相当冗长的代码,不知道从哪里开始发布此代码),我无法想象会对应用程序是否在启动时启动产生影响。我的所有图像和文件都已作为资源添加到项目中。我可以真正找到的唯一参考概述这个类似的场景在这个论坛上:application won't start on startup after adding a notifyicon它实际上看起来不像我当前的设置,因为我的notifyIcon对象和属性已经使用Visual Studio添加我没有手动编码。

当有正确的条目在注册表中时,是否有人知道可能导致程序在启动时无法启动的原因?我知道我还没有提供太多代码,如果我能提供其他任何信息,请告诉我,我很乐意这样做。

提前非常感谢你!

1 个答案:

答案 0 :(得分:0)

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

enter image description here

通过任务管理器启用/禁用在

设置注册表项

import random correct,number,left,right = 0,0,random.randint(6,10),random.randint(1,5) add =(left+right) sub =(left-right) mul =(left*right) StrAdd =("+") StrSub =("-") StrMul =("*") StrOp=StrAdd,StrSub,StrMul StrRandOp=random.choice(StrOp) print("\n\nwhat is\n",left,"",StrRandOp,"",right,) given = float(input("\nAnswer here: ")) while number < 10: if given == add: print("you got the answer right,well done") correct=correct+1 number=number+1 elif given == sub: print("you got the answer right,well done") correct=correct+1 number=number+1 elif given == mul: print("you got the answer right,well done") correct=correct+1 number=number+1 else: print("wrong") print("""Welldone you have answered all 10 questions and managed to get correct:""", correct) input("press enter to exit")

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

如果值以HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run开头,则启用它。如果它以另一个值开头(例如我的示例中为02 00 00)则会被禁用:

enter image description here