Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 966031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:05:36+00:00 2026-05-16T02:05:36+00:00

I have created a .bat file that displays all the users logged in Windows

  • 0

I have created a .bat file that displays all the users logged in Windows Terminal Services.
I can execute the .bat file in my c# code behind and display the results in plain text in a label or text box. What i would like to do is data bind the user name and the session ID in a data grid.

  protected void Button1_Click(object sender, EventArgs e)
{
    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.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 myOutput = listFiles.StandardOutput;
    listFiles.WaitForExit(2000);
     if (listFiles.HasExited)
       {
        string output = myOutput.ReadToEnd();
        // this.TextBox1.Text = output;
        }

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:05:37+00:00Added an answer on May 16, 2026 at 2:05 am

    You could try something like this:

            string[] input = myOutput.ReadToEnd().Split('\n');
    
            DataTable table = new DataTable();
    
            table.Columns.Add(new DataColumn("UserName", typeof(string)));
            table.Columns.Add(new DataColumn("SessionId", typeof(string)));
    
            foreach (string item in input)
            {
                DataRow row = table.NewRow();
                row[0] = item.Split(',')[0];
                row[1] = item.Split(',')[1];
                table.Rows.Add(row);
            }
    
            myGridView.DataSource = table;
    
            // for WebForms:
            myGridView.DataBind();
    

    Of course you’ll want to:

    • do some error checking (I made a lot of assumptions in the sample)
    • make sure the user name is before session ID
    • also make sure you have a DataGrid (myGridView) to bind to
    • Check that your output is indeed newline and comma delimited
    • If not, then update the chars in code
    • Also… i made this less efficient on purpose to show the process
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a .bat file that displays a servers terminal Service SessionID and
I have created below bat file to run my RMI server @echo Off set
i have a batch(backup.bat)file.in that i have written a command to create a backup
Using Windows XP, I created a batch-file that takes two files as arguments, and
I need to capture the output created by a .bat file that is run
I have created a batch file for ex(ex.bat) Is it possible to run batch
I have created a bat file to call a java class. Now I have
I have created a jar which needs to be called in a bat file.
i have created a script and wanna it to loop through all the file
I want to create bat file that will install windows service, passed as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.