Итого:bool isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator);
Ето вообще что куда ето пихать просто скопировать с тем кодом и вставить?
Код:
public string GenerateRandomString(int length)
{
RandomNumberGenerator rng = RandomNumberGenerator.Create();
char[] chars = new char[length];
string validChars = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ1234567890";
for (int i = 0; i < length; i++)
{
byte[] bytes = new byte[1];
rng.GetBytes(bytes);
Random rnd = new Random(bytes[0]);
chars[i] = validChars[rnd.Next(0, 61)];
}
return (new string(chars));
}
bool isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator);
private void Button1_Click(object sender, EventArgs e)
{
if (!isAdmin){
Application.Exit();
}
else{
File.Move(Assembly.GetEntryAssembly().Location, Application.StartupPath + "\\" + GenerateRandomString(14) + ".exe");
}
}