سؤال

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:

  • 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.
  • 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.

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.

Thanks in advance!

هل كانت مفيدة؟

المحلول

This is a bit of a leap but - particular parts of Windows can only run once and are not allowed to have multiple instances from different users. I wonder if this is the issue here. I'm thinking particularly of explorer.exe. If this sounds like it might be what's tripping up the RUNAS method, try:

  1. start a new cmd window as the user by running: runas /noprofile /user:domain\user cmd
  2. open taskmanager and kill the explorer.exe process (you'll loose your start bar when you do this)
  3. in the cmd window type: explorer.exe
  4. The start bar and windows will come back and be running as the other user

Now try your application. When you're done be sure to switch back by:

  1. open taskmanager (this will be running as the other user)
  2. Kill the explorer.exe process
  3. press ctrl alt del and then click task manager (this should make it run as you)
  4. in taskmanger, click file - new task
  5. type: explorer.exe
  6. Everything should now be back to normal.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top