Run process under diffrent user

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

    #1

    Run process under diffrent user

    Framework 1.1

    I want to start AcrobatReader to print a printjob under a specific username
    (so that the owner of the printjob is not the username of the application
    that the .net application runs under).

    So how can I start a process under another user? The password of the user is
    known. (I already have code to create user if needed)

    If this can be done easier in Framework 2.0 I can switch to that, but it
    would be my first 2.0 app so if it can be done with as much easy, or trouble,
    then I'd prefer 1.1.
  • Herfried K. Wagner [MVP]

    #2
    Re: Run process under diffrent user

    "Philip Wagenaar" <philip.wagenaa r@online.nospam > schrieb:[color=blue]
    > I want to start AcrobatReader to print a printjob under a specific
    > username
    > (so that the owner of the printjob is not the username of the application
    > that the .net application runs under).
    >
    > So how can I start a process under another user? The password of the user
    > is
    > known. (I already have code to create user if needed)
    >
    > If this can be done easier in Framework 2.0 I can switch to that, but it
    > would be my first 2.0 app so if it can be done with as much easy, or
    > trouble,
    > then I'd prefer 1.1.[/color]

    ..NET 1.0/1.1 doesn't provide managed support to do that.

    In .NET 2.0 you can use the 'Process' class:

    ..NET Framework Class Library -- 'ProcessStartIn fo.UserName' Property
    <URL:http://msdn2.microsoft .com/en-us/library/bbthyk23(en-US,VS.80).aspx>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Steven Cheng[MSFT]

      #3
      Re: Run process under diffrent user

      Hey Philip,

      I think Herfried's suggestion are reasonable. For .NET 1.X, we have to use
      unmanaged API to start process running under a specfic user... In .net
      2.0 the new ProcessStartInf o has been modified to support specific user
      credentials to start a new process under that specified account.... E.G:


      =============== ===============
      Sub StartNewProcess ()

      Dim psi As New ProcessStartInf o("notepad.exe" )
      psi.Domain = "machinenam e"
      psi.UserName = "username"
      Dim sstr As New System.Security .SecureString
      Dim pwd As String = "Password01 !"

      Dim chars() As Char = pwd.ToCharArray ()

      Dim i As Integer

      For i = 0 To chars.Length - 1
      sstr.AppendChar (chars(i))
      Next

      psi.Password = sstr
      psi.UseShellExe cute = False

      Process.Start(p si)

      Console.WriteLi ne("Sub Process started........ ...")

      Console.ReadLin e()


      End Sub
      =============== ===============

      Hope helps. Thanks,

      Steven Cheng
      Microsoft Online Support

      Get Secure! www.microsoft.com/security
      (This posting is provided "AS IS", with no warranties, and confers no
      rights.)




      --------------------
      | From: "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>
      | References: <8FCD2435-CC62-48B7-AE2C-C16F0F44E1DB@mi crosoft.com>
      | Subject: Re: Run process under diffrent user
      | Date: Thu, 8 Dec 2005 12:56:55 +0100
      | Lines: 27
      | MIME-Version: 1.0
      | Content-Type: text/plain;
      | format=flowed;
      | charset="Utf-8";
      | reply-type=original
      | Content-Transfer-Encoding: 7bit
      | X-Priority: 3
      | X-MSMail-Priority: Normal
      | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
      | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
      | Message-ID: <uBrL95##FHA.29 2@TK2MSFTNGP14. phx.gbl>
      | Newsgroups: microsoft.publi c.dotnet.langua ges.vb
      | NNTP-Posting-Host: v208-105.vps.tuwien. ac.at 128.131.208.105
      | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
      | Xref: TK2MSFTNGXA02.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:307728
      | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
      |
      | "Philip Wagenaar" <philip.wagenaa r@online.nospam > schrieb:
      | > I want to start AcrobatReader to print a printjob under a specific
      | > username
      | > (so that the owner of the printjob is not the username of the
      application
      | > that the .net application runs under).
      | >
      | > So how can I start a process under another user? The password of the
      user
      | > is
      | > known. (I already have code to create user if needed)
      | >
      | > If this can be done easier in Framework 2.0 I can switch to that, but it
      | > would be my first 2.0 app so if it can be done with as much easy, or
      | > trouble,
      | > then I'd prefer 1.1.
      |
      | .NET 1.0/1.1 doesn't provide managed support to do that.
      |
      | In .NET 2.0 you can use the 'Process' class:
      |
      | .NET Framework Class Library -- 'ProcessStartIn fo.UserName' Property
      | <URL:http://msdn2.microsoft .com/en-us/library/bbthyk23(en-US,VS.80).aspx>
      |
      | --
      | M S Herfried K. Wagner
      | M V P <URL:http://dotnet.mvps.org/>
      | V B <URL:http://classicvb.org/petition/>
      |
      |

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Run process under diffrent user

        "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> schrieb:[color=blue]
        > I think Herfried's suggestion are reasonable. For .NET 1.X, we have to use
        > unmanaged API to start process running under a specfic user...[/color]

        Sample:

        <URL:http://www.gssg.de/net_impersonate .htm>

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        Working...