|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace hackman3vilGuy.CodeProject.VistaSecurity.ElevateWithButton
{
public partial class AdminForm : Form
{
public AdminForm()
{
InitializeComponent();
if (!VistaSecurity.IsAdmin())
{
this.Text += " (Standard)";
VistaSecurity.AddShieldToButton(buttonGetElevation);
}
else
this.Text += " (Elevated)";
}
private void buttonGetElevation_Click(object sender, EventArgs e)
{
if (VistaSecurity.IsAdmin())
{
DoAdminTask();
}
else
{
VistaSecurity.RestartElevated();
}
}
private void DoAdminTask()
{
try
{
string fName = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
+ @"\Microsoft\Windows\Start Menu\VISTA.TXT";
if (System.IO.File.Exists(fName))
{
System.IO.File.Delete(fName);
MessageBox.Show("VISTA.TXT deleted");
}
else
{
System.IO.File.Create(fName).Close();
MessageBox.Show("VISTA.TXT created");
}
}
catch (UnauthorizedAccessException uacEx)
{
MessageBox.Show(uacEx.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.ToString());
}
}
private void buttonNoElevation_Click(object sender, EventArgs e)
{
DoAdminTask();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.