OpenProcessThe OpenProcess function opens an existing process object.
 
 VB4-32,5,6
Declare Function OpenProcess Lib "Kernel32.dll" ( _ 
           ByVal dwDesiredAccessas As Long, _ 
           ByVal bInheritHandle As Long, _ 
           ByVal dwProcId As Long _ 
) As Long 
 
  
VB.NET
System.Diagnostics.Process.GetProcessById   
Operating Systems Supported 
Requires Windows NT 3.1 or later; Requires Windows 95 or later 
 
  
Library 
kernel32 
 
  
Parameter Information 
?dwDesiredAccess
[in] Specifies the access to the process object. For operating systems that support security checking, this access is checked against any security descriptor for the target process. This parameter can be STANDARD_RIGHTS_REQUIRED or one or more of the following values.
PROCESS_ALL_ACCESS
Specifies all possible access flags for the process object.
PROCESS_CREATE_PROCESS
Used internally.
PROCESS_CREATE_THREAD
Enables using the process handle in the CreateRemoteThread function to create a thread in the process.
PROCESS_DUP_HANDLE
Enables using the process handle as either the source or target process in the DuplicateHandle function to duplicate a handle.
PROCESS_QUERY_INFORMATION
Enables using the process handle in the GetExitCodeProcess and GetPriorityClass functions to read information from the process object.
PROCESS_SET_QUOTA
Enables using the process handle in the AssignProcessToJobObject and SetProcessWorkingSetSize functions to set memory limits.
PROCESS_SET_INFORMATION
Enables using the process handle in the SetPriorityClass function to set the priority class of the process.
PROCESS_TERMINATE
Enables using the process handle in the TerminateProcess function to terminate the process.
PROCESS_VM_OPERATION
Enables using the process handle in the VirtualProtectEx and WriteProcessMemory functions to modify the virtual memory of the process.
PROCESS_VM_READ
Enables using the process handle in the ReadProcessMemory function to read from the virtual memory of the process.
PROCESS_VM_WRITE
Enables using the process handle in the WriteProcessMemory function to write to the virtual memory of the process.
SYNCHRONIZE
Windows NT/2000: Enables using the process handle in any of the wait functions to wait for the process to terminate.?bInheritHandle
[in] Specifies whether the returned handle can be inherited by a new process created by the current process. If TRUE, the handle is inheritable.?dwProcessId
[in] Specifies the identifier of the process to open.
 
 
  
Return Values 
If the function succeeds, the return value is an open handle of the specified process.If the function fails, the return value is NULL. To get extended error information, call GetLastError.
 
 
  

解决方案 »

  1.   

    address:http://www.allapi.net/apilist/apifunction.php?apifunction=OpenProcess
      

  2.   

    以同步方式来执行其他程序   有时候,我们需要让VB在执行完外部程序后再执行下一语句,这就需要使用API函数。   我们可通过OpenProcess和CloseHandle函数来检测调用软件的运行情况。这两个函数的声明如下:   Declare Function OpenProcess Lib ″kernel32″ Alias ″OpenProcess″ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long   Declare Function CloseHandle Lib ″kernel32″ Alias ″CloseHandle″ (ByVal hObject As Long) As Long   建立下面函数,用以判断程序是否在运行,如果是,则在运行时返回True。   Function IsRunning(ByVal ProgramID) As Boolean  ′传入进程标识ID     Dim hProgram As Long   ′被检测的程序进程句柄     hProgram=OpenProcess(0,False,ProgramID)     If Not hProgram=0 Then      IsRunning=True     Else      IsRunning=False     End If     CloseHandle hProgram   End Function