Exemple #1
0
        static void Main()
        {
            try
            {
                //获得当前登录的Windows用户标示
                System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
                //创建Windows用户主题
                Application.EnableVisualStyles();

                System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
                //判断当前登录用户是否为管理员
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                {
                    //如果是管理员,则直接运行
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((obj, args) => dumpHelper.TryDump("error.dmp"));
                    Application.EnableVisualStyles();
                    Application.Run(new MainForm());
                }
                else
                {
                    //创建启动对象
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    //设置运行文件
                    startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
                    //设置启动动作,确保以管理员身份运行
                    startInfo.Verb = "runas";
                    //如果不是管理员,则启动UAC
                    System.Diagnostics.Process.Start(startInfo);
                    //退出
                    System.Windows.Forms.Application.Exit();
                }
            }
            catch (Exception ex)
            {
                UIMessageBox.Show("程序发生严重错误!错误:" + ex.ToString(), "程序崩溃");
                LOG.WriteLog("程序发生严重错误!错误:" + ex.ToString());
                if (UIMessageBox.ShowAsk("程序崩溃,是否要发送服务信息给作者,以帮助作者更好的完善软件?"))
                {
                    sendMail.sendmail("*****@*****.**", "松之宅矿工", "*****@*****.**", "松之宅矿工QQ", "dump文件提交", string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "error.dmp"), "error.dmp", "smtp.126.com", "*****@*****.**", "VEABHRROROCBHXNQ");
                }
            }
        }
Exemple #2
0
 private static void 生成原版bat(string 启动参数)
 {
     try
     {
         string       桌面路径 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\松之宅原版.bat";
         StreamWriter 写入流  = new StreamWriter(桌面路径, false, System.Text.Encoding.GetEncoding("gb2312"));
         写入流.WriteLine("@echo off");
         写入流.WriteLine("echo 该文件由松之宅挖矿者(topool.top)自动生成, 仅供排查错误使用。");
         写入流.WriteLine("echo 使用之前请先停止挖矿,否则可能同时运行两个内核导致查错失败。");
         写入流.WriteLine("echo 启动参数:" + 启动参数);
         写入流.WriteLine(启动参数);
         写入流.WriteLine("pause");
         写入流.Flush();
         写入流.Close();
     }
     catch (Exception ex)
     {
         LOG.WriteLog(ex.ToString());
     }
     //Application.StartupPath + @"\nbminer.exe"
 }