×

VB VB.NET

如何用 VB.NET / C# 调用其它外部程序

Kalet Kalet 发表于2019-07-16 23:25:54 浏览434 评论0

抢沙发发表评论

 

如何用 VB.NET / C# 调用其它外部程序,在程序内部调用其他 EXE 可执行文件。

VB代码

1. 利用 Shell 调用程序

   

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Shell("Explorer.exe", AppWinStyle.NormalFocus)
    End Sub

   

2. 利用 Process 调用程序

  

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim proc As New Process
        proc.StartInfo.FileName = "Explorer.exe"
        proc.Start()
    End Sub

   

C#代码

需要引入 using System.Diagnostics;

   

            System.Diagnostics.Process proc = new System.Diagnostics.Process();   
            proc.StartInfo.FileName = @"C:\Windows\notepad.exe";   
            proc.Start();

   

shell 与 Process 调用的区别

shell只能返回processid,但不能返回hProcess 就是说,不能通过这个得到返回值进行进一步操作。shell虽然调用方便。代码相对简单,但是如果要牵扯到更改进程优先级。还是用Process相关函数,控制丰富一些。



转自:https://www.forece.net/post/4415.htm/amp

群贤毕至

访客