Process.Start与用户名挂起 [英] Process.Start with Username hangs

查看:86
本文介绍了Process.Start与用户名挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下C#Web服务正常工作,直到您取消注释行

设置UserName和Password。然后该过程以

指定的用户开始,但挂起处于挂起状态。实际上,任何

可执行文件都会出现这个问题;它不是特定于whoami.exe。

这当然是使用.NET 2.0(1.1不支持以不同的用户身份运行

进程)。这似乎是一个错误。任何人都可以评论吗?


<%@ WebService Language =" C#"类= QUOT; Kirk.ForkIt" %>


使用System;

使用System.IO;

使用System.Collections;

使用System.Security;

使用System.Web.Services;

使用System.Diagnostics;


命名空间Kirk

{

公共类ForkIt

{


[WebMethod]

public string Main()

{

Process p = new Process();

ProcessStartInfo pInfo = new

ProcessStartInfo(@c:\ windows \ system32 \whoami.exe");


SecureString password = new SecureString();

//在这里设置密码值。

password.AppendChar('s'');

password.AppendChar(''e'');

password.AppendChar(''c'');

password.AppendChar(''r'');

password.AppendChar(''e' ');

password.AppendChar('t'');


pInfo.UserName =" Administrator" ;;

pInfo.Password =密码;

pInfo.CreateNoWindow = true;

pInfo.UseShellExecute = false;

pInfo.RedirectStandardOutput = true;


p.StartInfo = pInfo;

p.Start();


String output = p .StandardOutput.ReadToEnd();

p.WaitForExit();


返回输出;

}

}

}

解决方案

hmmm


也许可以尝试将域名/计算机名称放在用户名前面:


pInfo.UserName =" MyComputer\Administrator";


不确定,我还没有在2.0中使用过这个功能


谢谢,但你的建议没有帮助。在ProcessStartInfo类中有一个域成员

,但将其设置为计算机名称

并没有帮助。无论如何,身份验证不是问题本身_

,因为我可以看到挂起的进程正在以指定的用户运行

(在这种情况下为Administrator)。我可以获得任何域帐户来运行

流程,这只是流程挂起 - 任何流程。


< blockquote>你运行的是什么操作系统和谁是呼叫者身份,即asp.net进程的

身份或冒充身份如果

模仿是活跃的吗?


威利。


" Kirk" <き*********** @ gmail.com>在留言中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

|以下C#Web服务正常工作,直到您取消注释行

|设置用户名和密码。然后该过程以

|开始指定的用户,但挂起处于挂起状态。事实上,任何

|可执行文件会出现此问题;它不是特定于whoami.exe。

|当然,这是使用.NET 2.0(1.1不支持以不同的用户身份运行

|进程)。这似乎是一个错误。任何人都可以

|评论?

|

| <%@ WebService Language =" C#"类= QUOT; Kirk.ForkIt" %>

|

|使用系统;

|使用System.IO;

|使用System.Collections;

|使用System.Security;

|使用System.Web.Services;

|使用System.Diagnostics;

|

|命名空间Kirk

| {

|公共类ForkIt

| {

|

| [WebMethod]

| public string Main()

| {

|过程p =新过程();

| ProcessStartInfo pInfo = new

| ProcessStartInfo(@c:\ windows \ system32 \whoami.exe");

|

| SecureString password = new SecureString();

| //在这里设置密码值。

| password.AppendChar('s'');

| password.AppendChar(''e'');

| password.AppendChar(''c'');

| password.AppendChar(''r'');

| password.AppendChar(''e'');

| password.AppendChar(''t'');

|

| pInfo.UserName =" Administrator";

| pInfo.Password =密码;

| pInfo.CreateNoWindow = true;

| pInfo.UseShellExecute = false;

| pInfo.RedirectStandardOutput = true;

|

| p.StartInfo = pInfo;

| p.Start();

|

| String output = p.StandardOutput.ReadToEnd();

| p.WaitForExit();

|

|返回输出;

| }

| }

| }

|


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.ForkIt" %>

using System;
using System.IO;
using System.Collections;
using System.Security;
using System.Web.Services;
using System.Diagnostics;

namespace Kirk
{
public class ForkIt
{

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

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

pInfo.UserName = "Administrator";
pInfo.Password = password;
pInfo.CreateNoWindow = true;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardOutput = true;

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

String output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

return output;
}
}
}

解决方案

hmmm

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

pInfo.UserName = "MyComputer\Administrator";

not sure, i havent used this feature in 2.0 yet


Thanks, but your suggestion doesn''t help. There is a Domain member for
the ProcessStartInfo 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.


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.googlegr oups.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.ForkIt" %>
|
| using System;
| using System.IO;
| using System.Collections;
| using System.Security;
| using System.Web.Services;
| using System.Diagnostics;
|
| namespace Kirk
| {
| public class ForkIt
| {
|
| [WebMethod]
| public string Main()
| {
| Process p = new Process();
| ProcessStartInfo pInfo = new
| ProcessStartInfo(@"c:\windows\system32\whoami.exe" );
|
| SecureString password = new SecureString();
| // set value for password here.
| password.AppendChar(''s'');
| password.AppendChar(''e'');
| password.AppendChar(''c'');
| password.AppendChar(''r'');
| password.AppendChar(''e'');
| password.AppendChar(''t'');
|
| pInfo.UserName = "Administrator";
| pInfo.Password = password;
| pInfo.CreateNoWindow = true;
| pInfo.UseShellExecute = false;
| pInfo.RedirectStandardOutput = true;
|
| p.StartInfo = pInfo;
| p.Start();
|
| String output = p.StandardOutput.ReadToEnd();
| p.WaitForExit();
|
| return output;
| }
| }
| }
|


这篇关于Process.Start与用户名挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆