title: Impersonate remote user in vb.net to access MS SQL Server
body: <p>I'm trying to impersonate a domain user over vpn. I am able to run management studio from the command prompt using the RUNAS command. However, I can't do the same with my vb application (.net 4.5, winforms, using VS 2012 Express) in either debug mode or published app. Here is what I tried:</p>
  
  <ul>
  <li>runas command of my application (from the location of the shortcut in Start Menu Programs, as well as the executable); in these cases, after I input the password in the command prompt, I get 'unknown user or bad password' error.</li>
  <li>I've tried the impersonate user within the code as indicated on several websites such as [http://williamfaulkner.co.uk/2009/04/vbnet-run-as-administrator-impersonate-a-user-2008/][1], which seems like a variation of that listed on MSDN that uses calls advapi.dll (I'm not really sure how it works). In this case, I also get 'unknown user or bad password' error when the code tries to query the SQL server.</li>
  </ul>
  
  <p>Does anyone have any explanation for these errors and/or how I might solve this. I'm assuming that if I can impersonate and run ssms, I should be able to do it within my vb app.</p>
  
  <p>Thanks in advance!</p>