0

我编写了使用 .bat 文件(代码:rwvinstat /server:servername)的代码,该文件填充了登录到 c# 中的终端服务会话的用户的 DataGrid。.bat 与应用程序一起存在于服务器上。文件,如果在服务器上手动执行,将正常运行。另外,如果我运行应用程序。在本地调用服务器上的 .bat 文件,它工作正常。

问题是当我在服务器上部署我的 Web 应用程序时,DataGrid 永远不会填充,也不会出现任何错误。我已授予 IUSER_MACHINENAME(和各种用户)的完全权限,并将虚拟目录权限设置为读取、运行、执行。我也将我的 web.conf fig 设置为:< "identity impersonate="true" userName="username" password="password"/>

这是我的源代码:

      using System;
      using System.Collections;
      using System.Configuration;
      using System.Data;
      using System.Linq;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.HtmlControls;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Xml.Linq;
      using System.Text;
      using System.Runtime.InteropServices;
      using System.Text.RegularExpressions;
      using System.IO;

        public partial class ilsap01_users : System.Web.UI.Page
        {

          protected void Page_Load(object sender, EventArgs e)
          {

     System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("C:\\listUsersIlsap01.bat"); 
    psi.RedirectStandardOutput = true;
    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    psi.UseShellExecute = false;
    System.Diagnostics.Process listFiles;
    listFiles = System.Diagnostics.Process.Start(psi);
    System.IO.StreamReader rawUserData = listFiles.StandardOutput;
    listFiles.WaitForExit(20000);
    try
    {
        DataTable table2 = new DataTable();
        table2.Columns.Add(new DataColumn("UserName", typeof(string)));
        table2.Columns.Add(new DataColumn("SessionId", typeof(string)));

        String myString = rawUserData.ReadToEnd();

        string exp = @"([\w_]+)"; ;


        MatchCollection matches = Regex.Matches(myString, exp, RegexOptions.IgnoreCase);

        IEnumerator en = matches.GetEnumerator();
        if (en.MoveNext())
        {
            while (en.MoveNext())
            {


                Match match = (Match)en.Current;

                if (en.Current.ToString() == "rdpwd")
                {
                    if (en.MoveNext())
                    {
                        if (en.Current.ToString() == "rdp")
                        {
                            en.MoveNext();
                            en.MoveNext();
                            en.MoveNext();

                            Match match_Item = (Match)en.Current;

                            string item = match_Item.Value;

                            en.MoveNext();

                            Match match_Item2 = (Match)en.Current;

                            string item2 = match_Item2.Value;

                            DataRow row = table2.NewRow();
                            row[0] = item.Split()[0];
                            row[1] = item2.Split()[0];

                            table2.Rows.Add(row);

                        }
                    }
                }
            }
        }

        this.displayUsers.DataSource = table2;
        this.displayUsers.DataBind();
    }

    catch (Exception ex)
    {
        Response.Write(ex);
    }
}
protected void dg_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
    Response.Redirect("ILSRF01_USERS.ASPX");
}
protected void Button1_Click(object sender, EventArgs e)
{

}
}
4

2 回答 2

0

您是否授予用户正在运行的应用程序池作为适当的远程桌面服务权限

此外,您可能会发现Cassia 库更容易用于您的目的。

于 2011-02-12T20:05:01.620 回答
0

批处理文件正在调用的可执行文件 (rwvinstat) 在系统路径中吗?您可能需要显式调用它 - c:\windows\system32\rwvinstat.exe 或它所在的任何位置。

于 2010-10-07T02:56:13.327 回答