| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace UAS_XmlAnalysor
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- SetAutoRun(Application.StartupPath+@"\"+ "UAS_XML解析器.exe", true);
- Application.Run(new Form1());
- }
- public static void SetAutoRun(string fileName, bool isAutoRun)
- {
- RegistryKey reg = null;
- try
- {
- if (!System.IO.File.Exists(fileName))
- throw new Exception("该文件不存在!");
- string name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
- reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
- if (reg == null)
- reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
- if (isAutoRun)
- reg.SetValue(name, fileName);
- else
- reg.SetValue(name, false);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.ToString());
- }
- finally
- {
- if (reg != null)
- reg.Close();
- }
- }
- }
- }
|