3
votes

I'm trying to return details of who is logged onto a server by executing the Quser windows command through C#, but can't get it to work. I've tried using a few of the guides out there but Ihaven't seen any for this instance. At the minute the command returns the following:

"Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0>"

String CmdText = @"quser /server:uk-dev-test-01";

Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = CmdText,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};

proc.Start();
String line = proc.StandardOutput.ReadToEnd();
1

1 Answers

1
votes

Use

String CmdText = @"/c quser /server:uk-dev-test-01";

i.e. add a /c before the quser command - otherwise, cmd.exe will not execute the command and will print exactly what you mentioned.