欢迎光临
我们一直在努力

.NET 程序,调用其它程序-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

.net 程序,调用其它程序

using system;

using system.diagnostics;

namespace jmv_demo

{

/// <summary>

/// cmdutility 的摘要说明。

/// </summary>

public class cmdutility

{

/// <summary>

/// 执行cmd.exe命令

/// </summary>

/// <param name="commandtext">命令文本</param>

/// <returns>命令输出文本</returns>

public string execommand(string commandtext)

{

return execommand(new string []{commandtext});

}

/// <summary>

/// 执行多条cmd.exe命令

/// </summary>

/// <param name="commandarray">命令文本数组</param>

/// <returns>命令输出文本</returns>

public string execommand(string [] commandtexts)

{

process p = new process();

p.startinfo.filename = "cmd.exe";

p.startinfo.useshellexecute = false;

p.startinfo.redirectstandardinput = true;

p.startinfo.redirectstandardoutput = true;

p.startinfo.redirectstandarderror = true;

p.startinfo.createnowindow = true;

string stroutput = null;

try

{

p.start();

foreach(string item in commandtexts)

{

p.standardinput.writeline(item);

}

p.standardinput.writeline("exit");

stroutput = p.standardoutput.readtoend();

p.waitforexit();

p.close();

}

catch(exception e)

{

stroutput = e.message;

}

return stroutput;

}

/// <summary>

/// 启动外部windows应用程序,隐藏程序界面

/// </summary>

/// <param name="appname">应用程序路径名称</param>

/// <returns>true表示成功,false表示失败</returns>

public bool startapp(string appname)

{

return startapp(appname,processwindowstyle.hidden);

}

/// <summary>

/// 启动外部应用程序

/// </summary>

/// <param name="appname">应用程序路径名称</param>

/// <param name="style">进程窗口模式</param>

/// <returns>true表示成功,false表示失败</returns>

public bool startapp(string appname,processwindowstyle style)

{

return startapp(appname,null,style);

}

/// <summary>

/// 启动外部应用程序,隐藏程序界面

/// </summary>

/// <param name="appname">应用程序路径名称</param>

/// <param name="arguments">启动参数</param>

/// <returns>true表示成功,false表示失败</returns>

public bool startapp(string appname,string arguments)

{

return startapp(appname,arguments,processwindowstyle.hidden);

}

/// <summary>

/// 启动外部应用程序

/// </summary>

/// <param name="appname">应用程序路径名称</param>

/// <param name="arguments">启动参数</param>

/// <param name="style">进程窗口模式</param>

/// <returns>true表示成功,false表示失败</returns>

public bool startapp(string appname,string arguments,processwindowstyle style)

{

bool blnrst = false;

process p = new process();

p.startinfo.filename = appname;//exe,bat and so on

p.startinfo.windowstyle = style;

p.startinfo.arguments = arguments;

try

{

p.start();

p.waitforexit();

p.close();

blnrst = true;

}

catch

{

}

return blnrst;

}

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » .NET 程序,调用其它程序-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章