sathenzar, on 26 April 2012 - 18:33, said:
I know that it's technically a bad practice to embed in the manifest file to require administrator rights but I'm not sure what else to do. I know you can make it to where a process within the program requires admin rights but that is not an option since the process would run every 15 min and the user would have to click accept each time (that would drive me nuts). I have to write to a various number of folders that the user has specified in various parts of their computer (program files, my documents, etc). Program files will not let me write to any of the folders without admin rights (which makes sense I guess). So currently I'm embedding in the program the manifest file to require admin rights. Am I stuck with this option? I have a backup program which backs up my client data, I have no way of knowing ahead of time which folders they will write to.
Here is how Julien Manici accomplishes this task in his code for "Windows7LoginBackgroundChanger":
/// <summary>
/// Execute as administrator the cmd file that enable the login screen change if enable == true.
/// Otherwise, execute the cmd file that disable the login screen change.
/// Shows an UAC prompt.
/// </summary>
bool launchCmd(bool enable)
{
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
if (enable)
p.StartInfo.Arguments = "/C \"" + path + "\\enable background change\"";
else
p.StartInfo.Arguments = "/C \"" + path + "\\disable background change\"";
p.StartInfo.Verb = "runas"; //shows the uac prompt
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (enable)
{
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
}
p.Start();
alreadyAskedPermission = true;
return true;
}
catch (Exception)
{
showMessage(Util.getText("error"), Util.getText("operationCanceled"), "");
}
return false;
}