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 581771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:36:55+00:00 2026-05-13T14:36:55+00:00

so I’ve tried Process and starting a cmd.exe and send commands directly to that

  • 0

so I’ve tried Process and starting a cmd.exe and send commands directly to that window. And then picking up the values written to the cmd.exe window.

The code looks like this:

Dim arrServers As ArrayList
    Dim s(ListBoxServers.Items.Count) As String

    ListBoxServers.Items.CopyTo(s, 0)
    arrServers = New ArrayList(s)

    Using P As New Process
        P.StartInfo.FileName = "cmd.exe"
        P.StartInfo.UseShellExecute = False
        P.StartInfo.RedirectStandardOutput = True
        P.StartInfo.RedirectStandardInput = True
        P.Start()
        For Each i In arrServers
            P.StandardInput.WriteLine("query user " & txtBoxUsername.Text & " /server:" & i)
        Next
        P.StandardInput.WriteLine("exit")
        Output = P.StandardOutput.ReadToEnd()
        Trace.WriteLine(Output)
        MsgBox(Output)
        P.WaitForExit()

    End Using

But is looks like it doesn’t “press enter” or something. Meaning, I don’t get any results from the command. I don’t even get a “‘command’ is not recognized as an internal or external command, operable program or batch file.” like you normally get if it doesn’t understand the syntax.

  • 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-13T14:36:56+00:00Added an answer on May 13, 2026 at 2:36 pm

    Imagine the following really simple batch file called “hello.bat”

    @ECHO OFF
    echo Hello
    

    You can call it and see “Hello” by using:

        'Will hold the results of the batch
        Dim Output As String
        'Create a new process object
        Using P As New Process()
            'Set the script to run
            P.StartInfo.FileName = "c:\scripts\hello.bat"
            'My script doesn't take argument but this is where you would pass them
            P.StartInfo.Arguments = ""
            'Required to redirect output, don't both worrying what it means
            P.StartInfo.UseShellExecute = False
            'Tell the system that you want to see the output
            P.StartInfo.RedirectStandardOutput = True
            'Start your batch
            P.Start()
            'Read the entire contents of the outout
            Output = P.StandardOutput.ReadToEnd()
            'Wait until the batch is done running
            P.WaitForExit()
        End Using
        'Do something with the output
        Trace.WriteLine("Batch produced : " & Output)
    

    Edit

    Here’s a version that doesn’t run a batch but instead runs a couple of standard commands. We start by firing up a command shell to pass things to. One thing that sucks is that its hard to run a command, read the output and then run another command. The code below runs two commands back-to-back and dumps the entire result into a string. If you have a need for running a command, processing, running another command, I think you’ll have to wire up something to StandardError and look at return codes. Before you do that, make sure you read up on problem with blocking and how other places solve it by wiring threads up such as here. Probably the easier way is to wrap this into a sub and call the sub once for each command.

        'Will hold all of the text
        Dim Output As String
        'Create a new process object
        Using P As New Process()
            'Set the script to run the standard command shell
            P.StartInfo.FileName = "cmd.exe"
            'Required to redirect output, don't both worrying what it means
            P.StartInfo.UseShellExecute = False
            'Tell the system that you want to read/write to it
            P.StartInfo.RedirectStandardOutput = True
            P.StartInfo.RedirectStandardInput = True
            'Start your batch
            P.Start()
            'Send your various commands
            P.StandardInput.WriteLine("dir c:\")
            P.StandardInput.WriteLine("ipconfig /all")
            'Very important, send the "exit" command otherwise STDOUT will never close the stream
            P.StandardInput.WriteLine("exit")
            'Read the entire stream
            Output = P.StandardOutput.ReadToEnd()
            'Wait until the batch is done running
            P.WaitForExit()
        End Using
        'Do something with the output
        Trace.WriteLine(Output)
    

    Edit 2

    I’m having problems with the “query user” command in general, I can’t get it to return anything for usernames with spaces in them even if I enclose the name in quotes. But here’s a version that uses “quser” instead which does the exact same thing as far as I know.

        'Will hold all of the text
        Dim Output As String
        'Create a new process object
        Using P As New Process()
            'Set the script to run the standard command shell
            P.StartInfo.FileName = "cmd.exe"
            'Required to redirect output, don't both worrying what it means
            P.StartInfo.UseShellExecute = False
            'Tell the system that you want to read/write to it
            P.StartInfo.RedirectStandardOutput = True
            P.StartInfo.RedirectStandardInput = True
            'Start your batch
            P.Start()
            'Send your various commands
            'Array of servers
            Dim arrServers() As String = New String() {"SERVER1", "SERVER2"}
            'Loop through array, wrap names with quotes in case they have spaces
            For Each S In arrServers
                P.StandardInput.WriteLine(String.Format("quser ""{0}"" /SERVER:{1}", Me.txtBoxUsername.Text, S))
            Next
            'Very important, send the "exit" command otherwise STDOUT will never close the stream
            P.StandardInput.WriteLine("exit")
            'Read the entire stream
            Output = P.StandardOutput.ReadToEnd()
            'Wait until the batch is done running
            P.WaitForExit()
        End Using
        'Do something with the output
        Trace.WriteLine(Output)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.