2013-01-14 111 views

回答

1

获取应用程序进程的父级并检查它是否由rdpinit.exe引发。如果是这样,那是一个RemoteApp。用于获取父进程ID(抱歉,vb.net)

简单的例子:

<Extension()> 
    Public Function GetParentProcessId(process As Process) As Integer 
     If process Is Nothing Then Throw New NullReferenceException() 

     Dim parentProcessId As Integer 
     Dim snapShot As IntPtr = IntPtr.Zero 

     Try 
      snapShot = CreateToolhelp32Snapshot(SnapshotFlags.Process, 0) 

      If snapShot <> IntPtr.Zero Then 
       Dim procEntry As New PROCESSENTRY32 
       procEntry.dwSize = CUInt(Marshal.SizeOf(GetType(PROCESSENTRY32))) 

       If Process32First(snapShot, procEntry) Then 
        Do 
         If process.Id = procEntry.th32ProcessID Then 
          parentProcessId = CInt(procEntry.th32ParentProcessID) 
          Exit Do 
         End If 
        Loop While Process32Next(snapShot, procEntry) 
       End If 
      End If 
     Catch ex As Exception 
      Throw 
     Finally 
      If snapShot <> IntPtr.Zero Then 
       CloseHandle(snapShot) 
      End If 
     End Try 

     Return parentProcessId 
    End Function 

现在你可以很容易地得到父进程。

Regards, Jan

相关问题