Language:

Läuft die Anwendung via Terminal Services?

Language: Deutsch
Programming Language: VB.NET
Published by: Roland [not registered]
Last Update: 5/4/2006
Views: 883

Description

Damit erhält man die Info, ob die Anwendung lokal läuft oder über Terminal Services/Remotedesktop aufgerufen wird.

Code

1 Imports System 2 Imports System.Runtime.InteropServices 3 4 Namespace Stuff.TSServices 5 Public Class Utilities 6 Public Enum WTS_INFO_CLASS 7 WTSInitialProgram 8 WTSApplicationName 9 WTSWorkingDirectory 10 WTSOEMId 11 WTSSessionId 12 WTSUserName 13 WTSWinStationName 14 WTSDomainName 15 WTSConnectState 16 WTSClientBuildNumber 17 WTSClientName 18 WTSClientDirectory 19 WTSClientProductId 20 WTSClientHardwareId 21 WTSClientAddress 22 WTSClientDisplay 23 WTSClientProtocolType 24 End Enum 25 <DllImport("Wtsapi32.dll")> _ 26 Public Shared Function WTSQuerySessionInformation(ByVal hServer As System.IntPtr, ByVal sessionId As Integer, ByVal wtsInfoClass As WTS_INFO_CLASS, ByRef ppBuffer As System.IntPtr, ByRef pBytesReturned As System.UInt32) As Boolean 27 End Function 28 29 <DllImport("Kernel32.dll")> _ 30 Public Shared Function WTSGetActiveConsoleSessionId() As Integer 31 End Function 32 33 <DllImport("wtsapi32.dll", ExactSpelling:=True, SetLastError:=False)> _ 34 Public Shared Sub WTSFreeMemory(ByVal memory As IntPtr) 35 End Sub 36 37 Public Const WTS_CURRENT_SERVER_HANDLE As Integer = -1 38 39 Public Shared Function GetIsRunningLocally() As Boolean 40 Dim buffer As System.IntPtr = IntPtr.Zero 41 Dim bytesReturned As System.UInt32 42 Dim sessionID As Integer 43 Try 44 Dim sessionInfo As Boolean = WTSQuerySessionInformation(System.IntPtr.Zero, WTS_CURRENT_SERVER_HANDLE, WTS_INFO_CLASS.WTSSessionId, buffer, bytesReturned) 45 sessionID = Marshal.ReadInt32(buffer) 46 Catch 47 Return True 48 Finally 49 WTSFreeMemory(buffer) 50 buffer = IntPtr.Zero 51 End Try 52 Dim currentSessionId As Integer = WTSGetActiveConsoleSessionId() 53 If currentSessionId = sessionID Then 54 Return True 55 Else 56 Return False 57 End If 58 End Function 59 End Class 60 End Namespace

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS