Yes, there are many articles related to elevating permissions when installing MSI packages. I have a twist on the issue that I can't find a good answer to. If I'm logged in as a user and I run my MSI elevation code (Below), the package installs but the current user actions are performed on the user I elevated the installer with.
For example, if the MSI adds a file to the CURRENT USER's desktop. The result of elevation (running as "Joe Admin") is the file gets put on Joe Admin's desktop -not the currently logged in user ("Sally User"). I have owned software that Elevates as Joe but puts the file on Sally's desktop as if she installed it. -I'd like to write my own. This is on a Windows 7 Machine, UAC is turned off.
Here is the non-working code. (Sally is logged in, Elevate as Joe -File goes to Joe's Desktop) (LoadUserProfile property was an attempt to solve this issue -didn't work).
Process watchThis = ImpersonateInstaller(@"c:\temp\Test.msi", "SuperJoePassword");
watchThis.WaitForExit();
private static Process ImpersonateInstaller(string msiPath, string Password)
{
Domain d = Domain.GetCurrentDomain();
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.LoadUserProfile = true;
process.StartInfo.FileName = @"C:\Windows\System32\msiexec.exe";
process.StartInfo.Arguments = string.Format(@"/i {0} REBOOT=ReallySuppress /qb-", msiPath);
process.StartInfo.WorkingDirectory = Environment.GetEnvironmentVariable("WINDIR");
process.StartInfo.UserName = "JoeAdmin";
process.StartInfo.Password = new SecureString();
process.StartInfo.Domain = d.ToString();
foreach (char c in Password.ToCharArray())
{
process.StartInfo.Password.AppendChar(c);
}
process.Start();
return process;
}