473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.Start with Username hangs

The following C# web service works fine until you uncomment the lines
setting UserName and Password. Then the process starts as the
specified user, but hangs in a suspended state. In fact, any
executable will exhibit this problem; it is not specific to whoami.exe.
This is with .NET 2.0, of course (1.1 does not support running a
process as a different user). This appears to be a bug. Can anyone
comment?

<%@ WebService Language="C#" Class="Kirk.For kIt" %>

using System;
using System.IO;
using System.Collecti ons;
using System.Security ;
using System.Web.Serv ices;
using System.Diagnost ics;

namespace Kirk
{
public class ForkIt
{

[WebMethod]
public string Main()
{
Process p = new Process();
ProcessStartInf o pInfo = new
ProcessStartInf o(@"c:\windows\ system32\whoami .exe");

SecureString password = new SecureString();
// set value for password here.
password.Append Char('s');
password.Append Char('e');
password.Append Char('c');
password.Append Char('r');
password.Append Char('e');
password.Append Char('t');

pInfo.UserName = "Administrator" ;
pInfo.Password = password;
pInfo.CreateNoW indow = true;
pInfo.UseShellE xecute = false;
pInfo.RedirectS tandardOutput = true;

p.StartInfo = pInfo;
p.Start();

String output = p.StandardOutpu t.ReadToEnd();
p.WaitForExit() ;

return output;
}
}
}

Feb 8 '06 #1
11 13331
hmmm

maybe try putting the domain/computer name in front of the username:

pInfo.UserName = "MyComputer\Adm inistrator";

not sure, i havent used this feature in 2.0 yet

Feb 8 '06 #2
Thanks, but your suggestion doesn't help. There is a Domain member for
the ProcessStartInf o class, but setting that to the computer name
doesn't help. Anyway, the authentication is not an issue _in itself_
as I can see that the hung process is running as the specified user
(Administrator in this case). I can get any domain account to run the
process, it's just that the process hangs -- any process.

Feb 8 '06 #3
What OS are you running this on and Who's the callers identity, that is the
identity of the asp.net process or the impersonating identity if
impersonation is active?

Willy.

"Kirk" <ki***********@ gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
| The following C# web service works fine until you uncomment the lines
| setting UserName and Password. Then the process starts as the
| specified user, but hangs in a suspended state. In fact, any
| executable will exhibit this problem; it is not specific to whoami.exe.
| This is with .NET 2.0, of course (1.1 does not support running a
| process as a different user). This appears to be a bug. Can anyone
| comment?
|
| <%@ WebService Language="C#" Class="Kirk.For kIt" %>
|
| using System;
| using System.IO;
| using System.Collecti ons;
| using System.Security ;
| using System.Web.Serv ices;
| using System.Diagnost ics;
|
| namespace Kirk
| {
| public class ForkIt
| {
|
| [WebMethod]
| public string Main()
| {
| Process p = new Process();
| ProcessStartInf o pInfo = new
| ProcessStartInf o(@"c:\windows\ system32\whoami .exe");
|
| SecureString password = new SecureString();
| // set value for password here.
| password.Append Char('s');
| password.Append Char('e');
| password.Append Char('c');
| password.Append Char('r');
| password.Append Char('e');
| password.Append Char('t');
|
| pInfo.UserName = "Administrator" ;
| pInfo.Password = password;
| pInfo.CreateNoW indow = true;
| pInfo.UseShellE xecute = false;
| pInfo.RedirectS tandardOutput = true;
|
| p.StartInfo = pInfo;
| p.Start();
|
| String output = p.StandardOutpu t.ReadToEnd();
| p.WaitForExit() ;
|
| return output;
| }
| }
| }
|
Feb 8 '06 #4
OS is Windows 2003 Server. I run IE6 and invoke the Web Service via
the Invoke button from the default generator for .asmx files. The asmx
file is also local to the web server; everything is on the same
machine.

I have impersonate set to true in my
C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \CONFIG\web.con fig file,
and I am logged in as a domain user (DOMAIN/SOFTINFO, same DOMAIN that
the server is in) with Administrative priviledges. When I invoke the
service, Environment.Dom ainName="SW-WEB"
Environment.Use rName="IUSR_SWD EVL2" (SW-WEB is the name of the machine,
SWDEVL2 was the previous name of the machine).

If I remove impersonation from my web.config, the service throws an
exception...Acc ess is Denied. Environment.Dom ainName="DOMAIN "
Environment.Use rName="SYSTEM". Not sure what SYSTEM really means, but
I suppose it doesn't have permission to create processes. Anyway,
that's why I enabled impersonation in the first place (plus it's how my
old ASP stuff works and I like it for our intranet).

I'm no expert, but my understanding is that impersonation will run my
Web Service thread as the client user, however, when my process forks,
it will run as the IIS user. I'm a bit confused, though, becuase I
would expect UserName to be "SOFTINFO" for the case where I have
impersonation turned on. Perhaps you can clarify this.

The Web Service is inline, and running from an Application Pool with
Identity set to Local System. I also set it to Network Service and
witness the same behavior. If I set it to Local Service I get the
following error when I Invoke the Web Service (this is not a problem
for me, but it might be a clue, I don't know):

System.InvalidO perationExcepti on: Unable to generate a temporary class
(result=1).
error CS2001: Source file 'C:\WINDOWS\TEM P\qa0vmnpy.0.cs ' could not be
found
error CS2008: No inputs specified

at System.Xml.Seri alization.Compi ler.Compile(Ass embly parent, String
ns, CompilerParamet ers parameters, Evidence evidence)
at
System.Xml.Seri alization.TempA ssembly.Generat eAssembly(XmlMa pping[]
xmlMappings, Type[] types, String defaultNamespac e, Evidence evidence,
CompilerParamet ers parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Seri alization.TempA ssembly..ctor(X mlMapping[]
xmlMappings, Type[] types, String defaultNamespac e, String location,
Evidence evidence)
at System.Xml.Seri alization.XmlSe rializer.FromMa ppings(XmlMappi ng[]
mappings, Evidence evidence)
at
System.Web.Serv ices.Protocols. XmlReturn.GetIn itializers(Logi calMethodInfo[]
methodInfos)
at
System.Web.Serv ices.Protocols. XmlReturnWriter .GetInitializer s(LogicalMethod Info[]
methodInfos)
at System.Web.Serv ices.Protocols. MimeFormatter.G etInitializers( Type
type, LogicalMethodIn fo[] methodInfos)
at System.Web.Serv ices.Protocols. HttpServerType. .ctor(Type type)
at System.Web.Serv ices.Protocols. HttpServerProto col.Initialize( )
at System.Web.Serv ices.Protocols. ServerProtocolF actory.Create(T ype
type, HttpContext context, HttpRequest request, HttpResponse response,
Boolean& abortProcessing )

Thanks,
Kirk

Feb 9 '06 #5

"Kirk" <ki***********@ gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
| OS is Windows 2003 Server. I run IE6 and invoke the Web Service via
| the Invoke button from the default generator for .asmx files. The asmx
| file is also local to the web server; everything is on the same
| machine.
|
| I have impersonate set to true in my
| C:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \CONFIG\web.con fig file,
| and I am logged in as a domain user (DOMAIN/SOFTINFO, same DOMAIN that
| the server is in) with Administrative priviledges. When I invoke the
| service, Environment.Dom ainName="SW-WEB"
| Environment.Use rName="IUSR_SWD EVL2" (SW-WEB is the name of the machine,
| SWDEVL2 was the previous name of the machine).
|
Environment.Use rName="IUSR_SWD EVL2"
That's an indication that you are impersonating 'the' "anonymous" user.

| If I remove impersonation from my web.config, the service throws an
| exception...Acc ess is Denied. Environment.Dom ainName="DOMAIN "
| Environment.Use rName="SYSTEM". Not sure what SYSTEM really means, but
| I suppose it doesn't have permission to create processes. Anyway,
| that's why I enabled impersonation in the first place (plus it's how my
| old ASP stuff works and I like it for our intranet).
|

That's an indication that you run your asp.net process as localsystem. Note
that you can't create another process using different user credentials (as
you do in your code) from a process that runs as localsystem (W2K3 and XP
SP2).

| I'm no expert, but my understanding is that impersonation will run my
| Web Service thread as the client user, however, when my process forks,
| it will run as the IIS user. I'm a bit confused, though, becuase I
| would expect UserName to be "SOFTINFO" for the case where I have
| impersonation turned on. Perhaps you can clarify this.
|

Yes, taht's because you haven enabled Windows authentication while
impersonating (see you web.config file), so you are impersonating the
default "anonymous" user which has the form IUSR_XXXXX, where XXXXX is the
machine name.

| The Web Service is inline, and running from an Application Pool with
| Identity set to Local System. I also set it to Network Service and
| witness the same behavior. If I set it to Local Service I get the
| following error when I Invoke the Web Service (this is not a problem
| for me, but it might be a clue, I don't know):
|

"Local Service" or (better) "local network" must be granted access rights to
the TEMP folder and a couple of other folder too.
Note that all of these question can better be answered when you post to the
asp or aspnet NG's, this NG is for C# only.
Willy.
Feb 9 '06 #6
Thanks. Your reply, some sleep, and a fresh pot of coffe have alerted
me to the fact that my virtual directory under IIS was set to allow
anonymous access -- not what I intended. So...I set it to integrated
Windows auth and now I see the DOMAIN user in Environment.Use rName when
I invoke the service (as expected). However, I get an Access is Denied
exception when I try to start the process when I set the
ProcesStartInfo UserName and Password to the local Administrator
account. If I don't set UserName and Password in ProcessStartInf o,
then the service runs fine. In that case, I see UserName is the domain
user I logged in as when challenged from the browser, and whoami.exe
returns "nt authority / system".

I suspect the issue is what you said: "Note that you can't create
another process using different user credentials (as you do in your
code) from a process that runs as localsystem (W2K3 and XP SP2)." I
assume the solution is to use an Application Pool to run the Web
Service in a process owned by a different user. So I set the
Configurable Identity section of the App Pool properties to use Local
Administrator (and added Administrator to the IIS_WPG group, and
granted user rights as specified here:
http://www.microsoft.com/technet/pro.../appisoa.mspx).
Now when I invoke without UserName set, whoami tells me it is the
local Administrator as expected. But if I set UserName, I still get
Access is Denied. What other access do I need to grant local
Administrator to allow it to create this process as a different user?

I will cross-post this to the aspnet NG.

Thanks, again.
Kirk

Feb 9 '06 #7
Willy, I hope you haven't given up on me. I'm getting no responses
from the other newsgroups. Do you have any further suggestions for me?

Thanks,
Kirk

Feb 10 '06 #8

"Kirk" <ki***********@ gmail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
| Thanks. Your reply, some sleep, and a fresh pot of coffe have alerted
| me to the fact that my virtual directory under IIS was set to allow
| anonymous access -- not what I intended. So...I set it to integrated
| Windows auth and now I see the DOMAIN user in Environment.Use rName when
| I invoke the service (as expected). However, I get an Access is Denied
| exception when I try to start the process when I set the
| ProcesStartInfo UserName and Password to the local Administrator
| account. If I don't set UserName and Password in ProcessStartInf o,
| then the service runs fine. In that case, I see UserName is the domain
| user I logged in as when challenged from the browser, and whoami.exe
| returns "nt authority / system".
|
| I suspect the issue is what you said: "Note that you can't create
| another process using different user credentials (as you do in your
| code) from a process that runs as localsystem (W2K3 and XP SP2)." I
| assume the solution is to use an Application Pool to run the Web
| Service in a process owned by a different user. So I set the
| Configurable Identity section of the App Pool properties to use Local
| Administrator (and added Administrator to the IIS_WPG group, and
| granted user rights as specified here:
|
http://www.microsoft.com/technet/pro.../appisoa.mspx).
| Now when I invoke without UserName set, whoami tells me it is the
| local Administrator as expected. But if I set UserName, I still get
| Access is Denied. What other access do I need to grant local
| Administrator to allow it to create this process as a different user?
|
| I will cross-post this to the aspnet NG.
And who's the user you set, is it a local user?
If it's a local user, can he launch the command from the command line (using
runas)
Willy.
Feb 10 '06 #9
I tried domain users as well as the local (server) administrator
account, which I thought for sure should work since that's what the
pool is running as, but still no luck. I can run "runas
/user:Administra tor "c:\windows\sys tem32\whoami.ex e" no problem. (I
can see that it is in fact running if I runas a batch file that calls
whoami.exe over and over so the cmd box doesn't disappear right away.)
I can also run it as domain users (I tried using a domain account
instead of Administrator to manage the pool, but that didn't help).

A quick recap of my config and stuff just to check sanity:

* Windows Server 2003 with .NET 2.0 SDK installed
* IIS virtual directory for web_services set to integrated Windows
authentication
* web_services use app pool WebServices
* WebServices app pool sets Identity Configurable: local server
Administrator account
* (I also ran aspnet_regiis.e xe -ga on Administrator just in case)
* Impersonate set to true in web.config; authentication Windows
* Browser connects to aspx page as a separate domain user with access
to aspx file

My basic web service to invoke whoami.exe works fine with this config
unless you set UserName and Password on ProcessStartInf o. All
UserNames will fail, but most striking is the local server
Administrator also fails (even though that's what the pool uses). The
result is an Access is Denied exception from Process.Start.

Thanks,
Kirk

Feb 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
14093
by: toby | last post by:
Can any one help? I'm trying to use System.Diagnostics.Process.Start to open legacy MS access aplications (ade and mdb files) and vb 6 .exe's using asp.net. There is something confusing going on?!? The files are all in the same network location, when I try and start the MSaccess files I get a "file not found" error (it does go as far as...
6
14177
by: kk | last post by:
hello to all, I want to call an exe file on other system(on the same LAN)though a webservice(by placing the dll).For that i use the following code in C#...... Process ps = new Process(); ps.StartInfo.FileName = exeFilePath ps.StartInfo.Arguments = arguments; ps.Start();
0
7191
by: Paul | last post by:
Hi, I'm trying to kick off the iiscnfg.vbs from a webservice to export a website's config to an xml file (And eventually populate other servers with the config). I initially tried this using the 1.1 framework, but discovered that when I used Process.Start() the user's credentials were not impersonated, it just kept using the asp.net's user,...
11
7390
by: Kirk | last post by:
The following C# web service works fine until you uncomment the lines setting UserName and Password. Then the process starts as the specified user, but hangs in a suspended state. In fact, any executable will exhibit this problem; it is not specific to whoami.exe. This is with .NET 2.0, of course (1.1 does not support running a process as a...
0
6667
by: Kirk | last post by:
The following C# web service works fine until you uncomment the lines setting UserName and Password. Then, Process.Start throws an Access is Denied Exception. This is with .NET 2.0, of course (1.1 does not support running a process as a different user). I'm running everything on Windows Server 2003. I have impersonation enabled in my...
6
3358
by: Alexander Widera | last post by:
hello, if i start a program (an exe-file) with Process.Start(...) I don't have the required permissions that the programm needs (i could start the programm but the program needs special rights). So I added the StartInfo.UserName and Password to the Process. Now the program starts, but it hangs... nothing happens. In the task-manager the...
10
6305
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden so that the window for the Console application is not visible. However, when using some of the 'advanced' properties of the StartInfo object,...
7
5606
by: christian13467 | last post by:
Hi, I'm using ASP.Net 2.0 with IIS 6.0 on windows server 2003 sp1. Calling a commandline program or a cmd file using Process.Start inside a webservice method. The call to Process.Start returns once after restarting the iis. A second call to my webservice method never returns. I found some post wich where fixed checking access rights. I...
4
2867
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a web page hosted on a unix driven file server. The user wants to have this file converted to a pdf. My page takes the query string and turns it into...
0
7484
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.