Blog Stats
  • Posts - 42
  • Articles - 0
  • Comments - 39
  • Trackbacks - 36

 

RunAs utility - this time with Code

Check this code out -

System.Diagnostics.ProcessStartInfo myProcess =
   new System.Diagnostics.ProcessStartInfo("Notepad.exe");

myProcess.UserName = "someusername"; //windows username
System.Security.SecureString password = new System.Security.SecureString();
// set value for password here.
myProcess.Password = password;
myProcess.UseShellExecute = false;
System.Diagnostics.Process.Start(myProcess);

What the above code does is, it runs the application notepad as the user "someusername".

Now that's just like RunAs - except it's programmatic !! :-) (.NET 2.0 only)


Feedback

# re: RunAs utility - this time with Code

Gravatar How about file.copy using this runas technique?

I'd like to see that.

Thanks, 1/23/2006 9:07 AM | Josh

Post a comment





 

Please add 6 and 4 and type the answer here:

 

 

Copyright © Vinayak