如何在代码中获取别人程序的参数(帮助)信息?

aquariusdeng 2009-06-24 04:58:32
就比如说shundow.exe,我在cmd窗口输入 shutdown.exe /?可以看到它的帮助信息,里面包含了它支持哪些参数,比如:

Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]
[/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

No args Display help. This is the same as typing /?.
/? Display help. This is the same as not typing any options.
/i Display the graphical user interface (GUI).
This must be the first option.
/l Log off. This cannot be used with /m or /d options.
/s Shutdown the computer.
/r Shutdown and restart the computer.
/g Shutdown and restart the computer. After the system is
rebooted, restart any registered applications.

。。。。

怎样在代码里头得到上面这些内容呢?
谢谢
...全文
93 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
aquariusdeng 2009-06-25
  • 打赏
  • 举报
回复
Thanks everybody
yanm7788 2009-06-24
  • 打赏
  • 举报
回复
Mark
wenblue7 2009-06-24
  • 打赏
  • 举报
回复
貌似用反射可以
顶顶看
cnartstorm 2009-06-24
  • 打赏
  • 举报
回复
学习
xxyping 2009-06-24
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
Execute("shutdown",0);
}


public static string Execute(string dosCommand, int outtime)
{
string output = "";
if (dosCommand != null && dosCommand != "")
{
Process process = new Process();//创建进程对象
ProcessStartInfo startinfo = new ProcessStartInfo();//创建进程时使用的一组值,如下面的属性
startinfo.FileName = "cmd.exe";//设定需要执行的命令程序
//以下是隐藏cmd窗口的方法
startinfo.Arguments = "/c" + dosCommand;//设定参数,要输入到命令程序的字符,其中"/c"表示执行完命令后马上退出
startinfo.UseShellExecute = false;//不使用系统外壳程序启动
startinfo.RedirectStandardInput = false;//不重定向输入
startinfo.RedirectStandardOutput = true;//重定向输出,而不是默认的显示在dos控制台上
startinfo.CreateNoWindow = true;//不创建窗口
process.StartInfo = startinfo;

try
{
if (process.Start())//开始进程
{
if (outtime == 0)
{ process.WaitForExit(); }
else
{ process.WaitForExit(outtime); }
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{

}
finally
{
if (process != null)
{ process.Close(); }
}
}
return output;
}


zgke 2009-06-24
  • 打赏
  • 举报
回复
System.Diagnostics.Process _ProcessCommand = new System.Diagnostics.Process();
_ProcessCommand.StartInfo.FileName = "Cmd.exe";
_ProcessCommand.StartInfo.Arguments = "/C DIR /?";
_ProcessCommand.StartInfo.UseShellExecute = false;
_ProcessCommand.StartInfo.CreateNoWindow = true;
_ProcessCommand.StartInfo.RedirectStandardOutput = true;
_ProcessCommand.Start();
_ProcessCommand.WaitForExit();

string _Text = _ProcessCommand.StandardOutput.ReadToEnd();
chenchangxiong 2009-06-24
  • 打赏
  • 举报
回复
呵呵 一个笨办法,把这个输出到一个temp文件中,然后读取
比如system("shutdown.exe /?>c:\\$$temp.txt");

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧