如何使用特定的用户名和密码启动IIS进程

本文关键字:密码 启动 IIS 进程 用户 何使用 | 更新日期: 2023-09-27 17:56:30

我正在尝试从我们的内部网站运行应用程序。当我使用Process.Start("notepad");时,我可以看到记事本进程在我们的 Web 服务器中启动,具有应用程序池设置中提到的默认标识。

但是我必须使用特定的用户名和密码开始该过程。所以我尝试运行这行代码

string password = "XXXXX";
System.Security.SecureString securePwd = new System.Security.SecureString();
foreach (char c in password)
{
    // Append the character to the password.
    securePwd.AppendChar(c);
}
Process.Start("notepad", "username", securePwd, "domain");

在这种情况下,我什至没有看到在 Web 服务器中启动任何记事本进程。执行的代码行,因为当我传递错误的密码时,我可以看到我的网页抛出"错误的用户名或密码"错误。

如何使用特定的用户名和密码启动IIS进程

感谢大家的回复。在这里,我得到了解决方案,现在我的流程从模拟用户开始。

https://learn.microsoft.com/en-US/troubleshoot/aspnet/spawn-process-under-impersonated-user

谢谢。

你写的代码对我来说看起来不错。也许问题是

我什至没有看到任何记事本进程

我会尝试以下方法

捕获 ID 并将其写出给客户端,例如

Process note = Process.Start("notepad", "username", securePwd, "domain");
Response.Write( note.ID ); //Or whatever mechanism you prefer. 

然后登录到服务器并使用PowerShell查询该过程

例如

PS C:'> get-process notepad  | Select ProcessName, Id 
ProcessName                                                                  Id
-----------                                                                  --
notepad                                                                    5512

Id 应与写入客户端的内容匹配