shellexecute
using system.runtime.interopservices;
public enum showwindowcommands : int
{
sw_hide = 0,
sw_shownormal = 1, //用最近的大小和位置显示,激活
sw_normal = 1,
sw_showminimized = 2,
sw_showmaximized = 3,
sw_maximize = 3,
sw_shownoactivate = 4,
sw_show = 5,
sw_minimize = 6,
sw_showminnoactive = 7,
sw_showna = 8,
sw_restore = 9,
sw_showdefault = 10,
sw_max = 10
}
[dllimport("shell32.dll")]
public static extern intptr shellexecute(
intptr hwnd,
string lpszop,
string lpszfile,
string lpszparams,
string lpszdir,
showwindowcommands fsshowcmd
);
调用
shellexecute(intptr.zero, "open", urlorpath, null, null, showwindowcommands.sw_shownormal);
urlorpath可为exe路径或者网页url(使用默认浏览器打开网页url)
使用ie打开网页url
shellexecute(null, "open", "iexplore", "http://www.csdn.net", null, sw_showmaximized);
process
using system.diagnostics;
private static string execute(string exepath, string parameters)
{
string result = string.empty;
using (process p = new process())
{
p.startinfo.useshellexecute = false;
p.startinfo.createnowindow = true;
p.startinfo.redirectstandardoutput = true;
p.startinfo.filename = exepath;
p.startinfo.arguments = parameters;
p.start();
p.waitforexit();
result = p.standardoutput.readtoend();
}
return result;
}
到此这篇关于c#运行外部程序的两种方法小结的文章就介绍到这了,更多相关c#运行外部程序内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论