hi every one I have a problem that I need to Create an application that Can get some files from path on server so if user on the PC is administrator the system working smoothly but if the user not an admin the system need to work like "Run AS..." then select the Administrator user !! and the question is how can i force the application to run as administrator user with Code ??
this is my Code
private void frmMain_Load(object sender, EventArgs e)
{
if (!IsUserAdministrator())
{
this.Text += " Not Admin";
RunAs("System_Updater.exe", "aMohamady@al-Sadhan.Com", "major@123");
}
else
{
this.Text += " Administrator";
}
}
and
public bool IsUserAdministrator()
{
bool isAdmin;
try
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch (UnauthorizedAccessException ex)
{
isAdmin = false;
}
catch (Exception ex)
{
isAdmin = false;
}
return isAdmin;
}
private SecureString MakeSecureString(string text)
{
SecureString secure = new SecureString();
foreach (char c in text)
{
secure.AppendChar(c);
}
return secure;
}
private void RunAs(string path, string username, string password)
{
ProcessStartInfo myProcess = new ProcessStartInfo(path);
myProcess.UserName = username;
myProcess.Password = MakeSecureString(password);
myProcess.UseShellExecute = false;
Process.Start(myProcess);
}
but when i used this code in a non administrator user the application start many times?? and I make restart for the windows to make it stop
Please any one can help me ............