ale*_*lex 20
这是您向启动添加应用程序的方式:
// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (!IsStartupItem())
// Add the value in the registry so that the application runs at startup
rkApp.SetValue("My app's name", Application.ExecutablePath.ToString());
Run Code Online (Sandbox Code Playgroud)
并删除它:
// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if(IsStartupItem())
// Remove the value from the registry so that the application doesn't start
rkApp.DeleteValue("My app's name", false);
Run Code Online (Sandbox Code Playgroud)
我的代码中的IsStartupItem函数:
private bool IsStartupItem()
{
// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rkApp.GetValue("My app's name") == null)
// The value doesn't exist, the application is not set to run at startup
return false;
else
// The value exists, the application is set to run at startup
return true;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20187 次 |
| 最近记录: |