[DllImport("kernel32.dll")]
public static extern int WinExec(string exeName, int operType);
不推荐使用以上代码。
ShellExecute
若ShellExecute函数调用成功,则返回值为被执行程序的实例句柄。若返回值小于32,则表示出现错误。
/// <summary> /// ShellExecute /// </summary> /// <param name="hwnd">指定父窗口句柄:ntPtr.Zero</param> /// <param name="lpszOp">指定要进行的操作:Open</param> /// <param name="lpszFile">指定要打开的文件名|路径</param> /// <param name="lpszParams">指定命令行参数: 0 | ""</param> /// <param name="lpszDir">用于指定默认目录:0 | ""</param> /// <param name="FsShowCmd">显示模式: 0:隐藏 1~11</param> /// <returns></returns> [DllImport("shell32.dll")] private static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd); /// <summary> /// 打开程序/文件夹 /// </summary> /// <param name="path">路径</param> /// <param name="FsShow">显示模式 默认1</param> public static void OpenFile(string path, int FsShow = 1) { ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder(@path), new StringBuilder(""), new StringBuilder(""), FsShow); }
标签:c#,StringBuilder,ShellExecute,指定,int,static,使用,new From: https://www.cnblogs.com/roak/p/16955559.html