none
What's the difference between process.start(startinfo) and impersonation RRS feed

  • Question

  • Hi everyone,

    Recently, I was stuck at the security issue in C#.

    We want to call one dll and use some methods in the dll with one specific account other than windows login account (like open sharepoint or some internal website). basically, we can use process.start(startinfo) to start it if it is EXE I found. But the dll we want to call in the code is a third part dll, we only hope some code (open sharepoint) can be run under specific windows account. I did some search, and found impersonation(please refer to the link below) can change user context. but I found the sharepoint still be opened by my windows login account not the account we impersonated. Is there anyone tell me how to fingure out my issue? Thanks a lot.

    http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User

    Thanks

    Winnie



    • Edited by Winnie.Wang Thursday, August 16, 2012 2:40 PM
    Thursday, August 16, 2012 10:17 AM

Answers

All replies

  • Hi Winnie,

    Welcome to the MSDN Forum.

    Please try this code:

                SecureString ss = new SecureString();
                foreach (char c in "YourPassword")
                {
                    ss.AppendChar(c);
                }
                Process.Start(@"iexplore sharepointSite", "yourName", ss, "domain");

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 17, 2012 7:20 AM
    Moderator
  • Thanks for your response Mike.

    It is a good point to start a application via Process.Start() via specific account. But How to use process.start it I want to start a method? in this method I want to initialize something and return something......

    Thanks

    Winnie

    Friday, August 17, 2012 8:00 AM
  • Hi Winnie,

    To run a method, you need to do it with Thread: http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx 

    And at the bottom part of this page, there is an example for your reference.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 20, 2012 8:14 AM
    Moderator
  • Thanks Mike.

    I checked the url you post. Seems that it only start a new thread with parameter. But I would like to start the process with specific account. I saw the filename is one parameter i have to input in the process. But I hope to start the process with one method or a batch of code. For example, how to run the following code with specific account? Please let me if anything is wrong. Thanks a lot.

     InternetExplorer ie = new InternetExplorer();
     IWebBrowserApp wb = (IWebBrowserApp)ie;
     wb.Visible = true;
     object o = null;
     wb.Navigate(MySharePointUrl, ref o, ref o, ref o, ref o);

    Thanks

    Winnie


    • Edited by Winnie.Wang Monday, August 20, 2012 10:45 AM
    Monday, August 20, 2012 10:36 AM
  • Hi Winnie,

    Generally, we say this process is belonged to one User, but we don't say this thread is belonged to a user. Thread is executed with a token, you can change it by this function: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379590(v=vs.85).aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 21, 2012 4:03 AM
    Moderator
  • Impersonation is when the current executing thread changes its credentials (usually temporarily) in order to do something with another user's credentials:

    http://wcfsecurity.codeplex.com/wikipage?title=How%20to%20impersonate%20and%20delegate%20using%20LogonUser%20Windows%20API


    Phil Wilson

    Thursday, August 23, 2012 6:25 PM