By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,160 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,160 IT Pros & Developers. It's quick & easy.

Run process under diffrent user

P: n/a
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.
Dec 8 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Philip Wagenaar" <ph*************@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 -- '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/>

Dec 8 '05 #2

P: n/a
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]" <hi***************@gmx.at>
| References: <8F**********************************@microsoft.co m>
| 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: <uB*************@TK2MSFTNGP14.phx.gbl>
| 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!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:307728
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| "Philip Wagenaar" <ph*************@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 -- '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/>
|
|

Dec 9 '05 #3

P: n/a
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> schrieb:
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...


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/>

Dec 9 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.