[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private extern static bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool CreateProcessWithLogonW(
string strUser, string strDomain, string strPassword, int intLogon, string strApplication,
string strCommand, int intCreation, int intEnvironment, string strDirectory,
int intStartup, PROCESSINFORMATION infProcess);
[StructLayout(LayoutKind.Sequential)]
private class PROCESSINFORMATION {
public IntPtr Process;
public IntPtr Thread;
public int ProcessId;
public int ThreadId;
}
//Excerpt from a private void in which I run a Windows
//Installer update as the domain admin
//If the computer is part of the MyDomain domain, the
//update must be run with administrative privileges
PROCESSINFORMATION prc = new PROCESSINFORMATION();
//I have found you must provide the full filename and path
//to the executable
if (Maintenance.CreateProcessWithLogonW(
"Administrator", "MYDOMAIN", "mypassword", 0,
@"C:\Windows\System32\msiexec.exe", strArgument,
0, 0, "", 0, prc)) {
Maintenance.CloseHandle(prc.Process);
Maintenance.CloseHandle(prc.Thread);
}