Run process under diffrent user

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Philip Wagenaar said:
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 -- 'ProcessStartInfo.UserName' Property
<URL:http://msdn2.microsoft.com/en-us/library/bbthyk23(en-US,VS.80).aspx>
 
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 ProcessStartInfo 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 ProcessStartInfo("notepad.exe")
psi.Domain = "machinename"
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.UseShellExecute = False

Process.Start(psi)

Console.WriteLine("Sub Process started...........")

Console.ReadLine()


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]" <[email protected]>
| References: <[email protected]>
| 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##[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: v208-105.vps.tuwien.ac.at 128.131.208.105
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:307728
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| > 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 -- 'ProcessStartInfo.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/>
|
|
 
Back
Top