用VB6,运行Notepad并且结束,应该怎么写?uExitCode应该如何获取?这是目前的代码(LastDllError返回值为6):Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
....
CurrentProcess = Shell("notepad.exe " & CurrentFile, vbNormalFocus)
MsgBox TerminateProcess(CurrentProcess, 0)
....
CurrentProcess = Shell("notepad.exe " & CurrentFile, vbNormalFocus)
MsgBox TerminateProcess(CurrentProcess, 0)
用OpenProcess打开PID
Dim objP As Object, lngPID&, ret& On Error Resume Next
Set objP = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_Process")
ret = objP.Create("Notepad", Null, Null, lngPID)
If lngPID = 0 Then MsgBox "发生错误,检查您有权限吗?"
End SubPrivate Sub Command2_Click() '关闭记事本
Dim objP As Object
For Each objP In GetObject("winmgmts:{impersonationLevel=impersonate}!//.").ExecQuery("select * from Win32_Process where Name='notepad.exe'")
objP.Terminate
Next
If Err <> 0 Then MsgBox "发生未知错误:" & Err.Description
End Sub
我对wmi不太了解,但是上面的代码显然没有给notepad设置参数Finally,thank you all!