0
点赞
收藏
分享

微信扫一扫

软件测试基础面试题

pipu 2023-11-06 阅读 45

1.Regedit自启动注册表路径

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

2.获取运行程序路径

SetAutoStart(AppDomain.CurrentDomain.FriendlyName, AppDomain.CurrentDomain.BaseDirectory);

3.添加到注册表中,如果注册表已经存在此程序,则修改路径

 private void SetAutoStart(string appName, string appPath)
 {
     try
     {
         RegistryKey runs = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         if (runs == null)
         {
             LOG.Warn("registry key empty => Key:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run}");
             return;
         }
         string path = appPath + appName;
         if (runs.GetValue(appName) != null)
         {
             if (runs.GetValue(appName).ToString() != path)
             {
                 runs.DeleteValue(appName);
                 LOG.InfoFormat("Successfully updated registry path. \nAppName:{0} Path:{1}", appName, path);
             }
         }
         runs.SetValue(appName, path);
         runs.Close();
     }
     catch (Exception ex)
     {
         LOG.Warn("registry key fail => ", ex);
     }
 }
举报

相关推荐

0 条评论