コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!IsAdministrator())
            {
                string elevation = "This feature requires to create web servers and does so using the HTTPListener class. " +
                                   "To listen externally this either requires admin privileges or you have to add each URL using netsh." +
                                   "You can either click 'Yes' to elevate this application (Only use in a trusted environment) or click 'No' and you can click through the individual elevation prompts that netsh requires to add each URL." +
                                   "When you close the application you will then have to click through the elevation prompts for removing the URLs.";

                DialogResult dialogResult = MessageBox.Show(elevation, "Not running as Administrator. Do you wish to elevate?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    ProcessStartInfo proc = new ProcessStartInfo();
                    proc.UseShellExecute  = true;
                    proc.WorkingDirectory = Environment.CurrentDirectory;
                    proc.FileName         = Application.ExecutablePath;
                    proc.Verb             = "runas";

                    try
                    {
                        Process.Start(proc);
                    }
                    catch
                    {
                        return;
                    }

                    Application.Exit();
                }
            }
            ComeGetIt comegetit = new ComeGetIt();

            comegetit.Show();
        }
コード例 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!IsAdministrator())
            {

                string elevation = "This feature requires to create web servers and does so using the HTTPListener class. " +
                         "To listen externally this either requires admin privileges or you have to add each URL using netsh." +
                         "You can either click 'Yes' to elevate this application (Only use in a trusted environment) or click 'No' and you can click through the individual elevation prompts that netsh requires to add each URL." +
                         "When you close the application you will then have to click through the elevation prompts for removing the URLs.";

                DialogResult dialogResult = MessageBox.Show(elevation, "Not running as Administrator. Do you wish to elevate?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    ProcessStartInfo proc = new ProcessStartInfo();
                    proc.UseShellExecute = true;
                    proc.WorkingDirectory = Environment.CurrentDirectory;
                    proc.FileName = Application.ExecutablePath;
                    proc.Verb = "runas";

                    try
                    {
                        Process.Start(proc);
                    }
                    catch
                    {
                        return;
                    }

                    Application.Exit();
                }
           
            }
            ComeGetIt comegetit = new ComeGetIt();
            comegetit.Show();
        }