在C#中执行Quser windows命令;将结果返回String [英] Executing Quser windows command in C#; Returning result to String

查看:565
本文介绍了在C#中执行Quser windows命令;将结果返回String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过执行Quser windows命令通过C#返回谁登录到服务器的详细信息,但不能让它工作。我试过使用一些指南,但我没有看到任何这个实例。在命令返回以下:

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 [版本6.1.7601]版权所有(c)2009 Microsoft Corporation。保留所有权利。C:\ Program文件(x86)\Common Files \Microsoft Shared\DevServer\10.0>

"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();


推荐答案

使用

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

quser 命令之前添加 / c - 否则,cmd.exe将不会执行命令,你提到。

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

这篇关于在C#中执行Quser windows命令;将结果返回String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆