在c#中用什么代码可以调用外部程序? 就像在vb中的shell
2个回答
展开全部
相当于填写了 &H100000
'即 pHnd = OpenProcess(SYNCHRONIZE, 0, pId) 等于 pHnd = OpenProcess(&H100000, 0, pId)
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
'引用系统 API “OpenProcess” 用以获得指定程序进程句柄
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
'引用系统 API “CloseHandle” 关闭句柄
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'引用系统 API “WaitForSingleObject” 用以等待指定句柄的进程执行
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
' 程序范例:(以执行 Notepad 程序为例)
Private Sub Command1_Click()
Dim pId As Long, pHnd As Long ' 分别声明 Process Id 及 Process Handle
pId = Shell("Notepad", vbNormalFocus) ' Shell 传回 Process Id 如 notepad 的 进程ID
pHnd = OpenProcess(SYNCHRONIZE, 0, pId) ' 取得 Process Handle 得到 notepad 的进程句柄
If pHnd <> 0 Then '句柄获得成功 则执行if内语句
Call WaitForSingleObject(pHnd, INFINITE) ' 无限等待,直到程序结束
Call CloseHandle(pHnd) '释放句柄
End If
MsgBox "执行结束"
End Sub
我也是菜鸟 只能解释成这样了
'即 pHnd = OpenProcess(SYNCHRONIZE, 0, pId) 等于 pHnd = OpenProcess(&H100000, 0, pId)
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
'引用系统 API “OpenProcess” 用以获得指定程序进程句柄
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
'引用系统 API “CloseHandle” 关闭句柄
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'引用系统 API “WaitForSingleObject” 用以等待指定句柄的进程执行
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
' 程序范例:(以执行 Notepad 程序为例)
Private Sub Command1_Click()
Dim pId As Long, pHnd As Long ' 分别声明 Process Id 及 Process Handle
pId = Shell("Notepad", vbNormalFocus) ' Shell 传回 Process Id 如 notepad 的 进程ID
pHnd = OpenProcess(SYNCHRONIZE, 0, pId) ' 取得 Process Handle 得到 notepad 的进程句柄
If pHnd <> 0 Then '句柄获得成功 则执行if内语句
Call WaitForSingleObject(pHnd, INFINITE) ' 无限等待,直到程序结束
Call CloseHandle(pHnd) '释放句柄
End If
MsgBox "执行结束"
End Sub
我也是菜鸟 只能解释成这样了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process prcShell = new System.Diagnostics.Process();
prcShell.StartInfo.FileName = "notepad.exe";
prcShell.Start();
}
{
System.Diagnostics.Process prcShell = new System.Diagnostics.Process();
prcShell.StartInfo.FileName = "notepad.exe";
prcShell.Start();
}
更多追问追答
追问
这句代码只能调用到系统里面的程序,那假如我要调用到QQ?怎么写呢?
追答
prcShell.StartInfo.FileName = "notepad.exe";
将"notepad.exe"替换成QQ.exe的完整路径即可。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询