Run with Administrator Credentials

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JM

    Run with Administrator Credentials

    Hi

    Is there a way to invoke an external program in C# with Administrator
    credentials? You know run an external VBS or batch?

    Any reference material would be useful.

    TIA
  • Willy Denoyette [MVP]

    #2
    Re: Run with Administrator Credentials


    "JM" <JM@discussions .microsoft.com> wrote in message
    news:07DE6F0A-55A0-48CB-AE93-2B55448DD6B2@mi crosoft.com...[color=blue]
    > Hi
    >
    > Is there a way to invoke an external program in C# with Administrator
    > credentials? You know run an external VBS or batch?
    >
    > Any reference material would be useful.
    >
    > TIA[/color]

    Yes, there is, you have to call Win32's CreateProcessWi thLogonW using
    PInvoke., or wait for v2.0 of the framework.
    Note that this won't work when called from a service.

    Willy.


    Comment

    • Ken Varn

      #3
      Re: Run with Administrator Credentials

      Check out WindowsIdentity class in System.Security .Principal.

      There is an Impersonate() method that will do what you are trying to
      accomplish. The missing link with this class is that you have to obtain an
      access token handle to use it. The only way I know of doing this is by
      pinvoking one of the Win32 security functions like LogonUser().

      --
      -----------------------------------
      Ken Varn
      Senior Software Engineer
      Diebold Inc.

      EmailID = varnk
      Domain = Diebold.com
      -----------------------------------
      "JM" <JM@discussions .microsoft.com> wrote in message
      news:07DE6F0A-55A0-48CB-AE93-2B55448DD6B2@mi crosoft.com...[color=blue]
      > Hi
      >
      > Is there a way to invoke an external program in C# with Administrator
      > credentials? You know run an external VBS or batch?
      >
      > Any reference material would be useful.
      >
      > TIA[/color]


      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Run with Administrator Credentials


        "Ken Varn" <nospam> wrote in message
        news:Oz7k1l1TFH A.3184@TK2MSFTN GP15.phx.gbl...[color=blue]
        > Check out WindowsIdentity class in System.Security .Principal.
        >
        > There is an Impersonate() method that will do what you are trying to
        > accomplish. The missing link with this class is that you have to obtain
        > an
        > access token handle to use it. The only way I know of doing this is by
        > pinvoking one of the Win32 security functions like LogonUser().
        >
        > --
        > -----------------------------------
        > Ken Varn
        > Senior Software Engineer
        > Diebold Inc.
        >[/color]


        Ken,

        No it won't. OP's needs to spawn another process that must run as
        administrator.
        When creating a process from an impersonating thread, the process will use
        the callers PROCESS identity, not the impersonating thread's identity.

        Willy.


        Comment

        Working...