注册 登录
编程论坛 C# 论坛

[求助]C#中实现VB6的SHELL

freeforever 发布于 2016-01-19 09:06, 2672 次点击
VB6中:
dim ptr as long
ptr = shell("notepad.exe",1)
这个ptr值为运行的notepad的PID。

在C#中有Process类,但实质是调用API中的WinExec函数,返回的是执行命令是否成功及错误结果。
怎样实现执行一个外部程序,得到的是执行程序的PID?
谢谢
2 回复
#2
freeforever2016-01-19 09:32
int Run(string exepath)
        {
            int res = 0;
            using (Process p = new Process())
            {
                p.StartInfo.FileName = exepath;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                res = p.Start() ? p.Id : 0;
            }
            return res;
        }
我短路了,谢谢看过贴的兄弟们
#3
qq10235692232016-01-30 23:23
学习了。
1