c#使用ShellExecute

c#使用ShellExecute | Id | Title | DateAdded | SourceUrl | PostType | Body | BlogId | Description | DateUpdated | IsMarkdown | EntryName | CreatedTime | IsActive | AutoDesc | AccessPermission |

| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------|
| 16955559| c#使用ShellExecute | 2022-12-06T15:54:00| | BlogPost|

[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);
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;summary&gt;</span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> 打开程序/文件夹
    </span><span style="color: #808080;">///</span> <span style="color: #808080;">&lt;/summary&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="path"&gt;</span><span style="color: #008000;">路径</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #808080;">///</span> <span style="color: #808080;">&lt;param name="FsShow"&gt;</span><span style="color: #008000;">显示模式 默认1</span><span style="color: #808080;">&lt;/param&gt;</span>
    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> OpenFile(<span style="color: #0000ff;">string</span> path, <span style="color: #0000ff;">int</span> FsShow = <span style="color: #800080;">1</span><span style="color: #000000;">)
    {
        ShellExecute(IntPtr.Zero, </span><span style="color: #0000ff;">new</span> StringBuilder(<span style="color: #800000;">"</span><span style="color: #800000;">Open</span><span style="color: #800000;">"</span>), <span style="color: #0000ff;">new</span> StringBuilder(@path), <span style="color: #0000ff;">new</span> StringBuilder(<span style="color: #800000;">""</span>), <span style="color: #0000ff;">new</span> StringBuilder(<span style="color: #800000;">""</span><span style="color: #000000;">), FsShow);
    }</span></pre>
复制代码

 

| 648658| 磁力搜索| 2022-12-06T16:09:00| false| | 2022-12-06T15:53:50.07| true| [DllImport("kernel32.dll")] public static extern int WinExec(string exeName, int operType); 不推荐使用以上代码。 ShellExecute若ShellExecute函数调用成功,则返回值为被执行程序的实例句柄| Anonymous|
posted @   RalphLauren  阅读(54)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示