title: Process.Start with different credentials with UAC on
body: <p>I am trying to start another process with Process.Start running under different credentials with the UAC turned on.  I get the following error:</p>
  
  <blockquote>
    <p>System.ComponentModel.Win32Exception:
    Logon failure: user account
    restriction. Possible reasons are
    blank passwords not allowed, logon
    hour restrictions, or a policy
    restriction has been enforced    at
    System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
    startInfo)    at
    System.Diagnostics.Process.Start()<br>
    at
    System.Diagnostics.Process.Start(ProcessStartInfo
    startInfo)</p>
  </blockquote>
  
  <p>If I turn off UAC, it works fine.  If I start the process without specifying username and password, it works fine.  Below is a copy of the code:</p>
  
  <pre><code>            ProcessStartInfo processInfo = new ProcessStartInfo();
              processInfo.Verb = "runas";
              processInfo.FileName = command;
              processInfo.Arguments = parameters;
              processInfo.UserName = txtUserName.Text;
              processInfo.Password = password;
              processInfo.Domain = "myDomain";
              processInfo.UseShellExecute = false;
              processInfo.LoadUserProfile = true;
  
              Process.Start(processInfo);
  </code></pre>
  
  <p>I believe this has something to do with the desktop session, but am not sure why it works when UAC is off.</p>
  
  <p>Any ideas on how to get this to work without turning off UAC, modifying the registry, or changing local/group policies would greatly be appreciated.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The Process that has the code above is started as an admin:</p>
  
  <pre><code>      static void Main(string[] args)
        {
           //make sure we are running with admin privileges
           if (VerifyIsAdmin())
           {
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new MyApp(args));
           }
        }
  
        private static bool VerifyIsAdmin()
        {
           WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
           bool isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
           if (!isAdmin)
           {
              ProcessStartInfo processInfo = new ProcessStartInfo();
              processInfo.Verb = "runas";
              processInfo.FileName = Application.ExecutablePath;
              Process.Start(processInfo);
           }
           return isAdmin;
        }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Tried <a href="http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/3e2a3345bdd184d6?pli=1" rel="noreferrer">CreateProcessWithLogonW</a> ... Had same problem.  </p>
  
  <p>After further searching, looks like it is a problem with the Group Policy requiring smart card logon (scforceoption).  That being said, I still don't understand why it works when UAC is off.  It should still require smart card on logon.  </p>
  
  <p>It doesn't look like I am going to be able to get around this.  Any insight/advice would be appreciated.</p>