有没有办法从用 C# 编写的应用程序中检测它是否作为使用 RDP 的远程应用程序启动?
问问题
1025 次
1 回答
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
现在您可以轻松获取父进程。
问候,扬
于 2013-08-14T05:40:30.230 回答