'Written by Jason Janofsky - jasonj@valleyins.com - 9/23/2006
Imports System.IO
Public Class Connection
Inherits TreeNode
#Region "Vars"
'Vars for all
Private oName As String
Private oFullAddress As String
Private oGuid As String
Private oTimesConnected As Integer
Private oLastConnect As DateTime
Private oPrefCon As Integer '0=RDP, 1=VNC, 2=Telnet
'Vars for VNC
Private oUseLocalCursor As Byte
Private oUseDesktopResize As Byte
Private oFullScreen As Byte
Private oFullColour As Byte
Private oLowColourLevel As Integer
Private oPreferredEncoding As String
Private oAutoSelect As Byte
Private oSharedVal As Byte
Private oSendPtrEvents As Byte
Private oSendKeyEvents As Byte
Private oSendCutText As Byte
Private oAcceptCutText As Byte
Private oDisableWinKeys As Byte
Private oEmulate3 As Byte
Private oPointerEventInterval As Integer
Private oMonitor As String
Private oMenuKey As String
Private oAutoReconnect As Byte
'Vars for RDP
Private oScreenMode As Integer
Private oDesktopWidth As Integer
Private oDesktopHeight As Integer
Private oSessionBPP As Integer
Private oWinPosStr As String
Private oCompression As Integer
Private oKeyboardHook As Integer
Private oAudioMode As Integer
Private oRedirectPrinters As Integer
Private oRedirectComPorts As Integer
Private oRedirectSmartCards As Integer
Private oRedirectClipBoard As Integer
Private oRedirectPosDevices As Integer
Private oDriveStoreDirect As String
Private oDisplayConnectionBar As Integer
Private oAutoReconnection As Integer
Private oAuthenticationLevel As Integer
Private oPromptForCredentials As Integer
Private oNegotiateSecurityLayer As Integer
Private oUsername As String
Private oDomain As String
Private oRemoteApplicationMode As Integer
Private oAlternateShell As String
Private oShellWorkingDirectory As String
Private oDisableWallpaper As Integer
Private oDisableFullWindowDrag As Integer
Private oAllowDesktopComposition As Integer
Private oAllowFontSmoothing As Integer
Private oDisableMenuAnims As Integer
Private oDisableThemes As Integer
Private oDisableCursorSettings As Integer
Private oBitMapCachePersistEnable As Integer
Private oGatewayHostName As String
Private oGateWayUsageMethod As Integer
Private oGateWayCredentialSource As Integer
Private oGateWayProfileUsageMethod As Integer
#End Region
#Region "Props"
Public Property FullAddress() As String
Get
Return oFullAddress
End Get
Set(ByVal value As String)
oFullAddress = value
End Set
End Property
Public Property PrefCon() As Integer
Get
Return oPrefCon
End Get
Set(ByVal value As Integer)
oPrefCon = value
End Set
End Property
Public Property LastConnect() As DateTime
Get
Return oLastConnect
End Get
Set(ByVal value As DateTime)
Try
value = CDate(value)
Catch
value = #1/1/1900#
End Try
oLastConnect = value
End Set
End Property
Public Property TimesConnected() As Integer
Get
Return oTimesConnected
End Get
Set(ByVal value As Integer)
oTimesConnected = value
End Set
End Property
Public Property Guid() As String
Get
Return oGuid
End Get
Set(ByVal value As String)
oGuid = value
End Set
End Property
Public Property UseLocalCursor() As Byte
Get
Return oUseLocalCursor
End Get
Set(ByVal value As Byte)
oUseLocalCursor = value
End Set
End Property
Public Property UseDesktopResize() As Byte
Get
Return oUseDesktopResize
End Get
Set(ByVal value As Byte)
oUseDesktopResize = value
End Set
End Property
Public Property FullScreen() As Byte
Get
Return oFullScreen
End Get
Set(ByVal value As Byte)
oFullScreen = value
End Set
End Property
Public Property FullColour() As Byte
Get
Return oFullColour
End Get
Set(ByVal value As Byte)
oFullColour = value
End Set
End Property
Public Property LowColourLevel() As Integer
Get
Return oLowColourLevel
End Get
Set(ByVal value As Integer)
oLowColourLevel = value
End Set
End Property
Public Property PreferredEncoding() As String
Get
Return oPreferredEncoding
End Get
Set(ByVal value As String)
oPreferredEncoding = value
End Set
End Property
Public Property AutoSelect() As Byte
Get
Return oAutoSelect
End Get
Set(ByVal value As Byte)
oAutoSelect = value
End Set
End Property
Public Property SharedVal() As Byte
Get
Return oSharedVal
End Get
Set(ByVal value As Byte)
oSharedVal = value
End Set
End Property
Public Property SendPtrEvents() As Byte
Get
Return oSendPtrEvents
End Get
Set(ByVal value As Byte)
oSendPtrEvents = value
End Set
End Property
Public Property SendKeyEvents() As Byte
Get
Return oSendKeyEvents
End Get
Set(ByVal value As Byte)
oSendKeyEvents = value
End Set
End Property
Public Property SendCutText() As Byte
Get
Return oSendCutText
End Get
Set(ByVal value As Byte)
oSendCutText = value
End Set
End Property
Public Property AcceptCutText() As Byte
Get
Return oAcceptCutText
End Get
Set(ByVal value As Byte)
oAcceptCutText = value
End Set
End Property
Public Property DisableWinKeys() As Byte
Get
Return oDisableWinKeys
End Get
Set(ByVal value As Byte)
oDisableWinKeys = value
End Set
End Property
Public Property Emulate3() As Byte
Get
Return oEmulate3
End Get
Set(ByVal value As Byte)
oEmulate3 = value
End Set
End Property
Public Property PointerEventInterval() As Integer
Get
Return oPointerEventInterval
End Get
Set(ByVal value As Integer)
oPointerEventInterval = value
End Set
End Property
Public Property Monitor() As String
Get
Return oMonitor
End Get
Set(ByVal value As String)
oMonitor = value
End Set
End Property
Public Property MenuKey() As String
Get
Return oMenuKey
End Get
Set(ByVal value As String)
oMenuKey = value
End Set
End Property
Public Property AutoReconnect() As Byte
Get
Return oAutoReconnect
End Get
Set(ByVal value As Byte)
oAutoReconnect = value
End Set
End Property
Public Property ScreenMode() As Integer
Get
Return oScreenMode
End Get
Set(ByVal value As Integer)
oScreenMode = value
End Set
End Property
Public Property DesktopWidth() As Integer
Get
Return oDesktopWidth
End Get
Set(ByVal value As Integer)
oDesktopWidth = value
End Set
End Property
Public Property DesktopHeight() As Integer
Get
Return oDesktopHeight
End Get
Set(ByVal value As Integer)
oDesktopHeight = value
End Set
End Property
Public Property SessionBPP() As Integer
Get
Return oSessionBPP
End Get
Set(ByVal value As Integer)
oSessionBPP = value
End Set
End Property
Public Property WinPosStr() As String
Get
Return oWinPosStr
End Get
Set(ByVal value As String)
oWinPosStr = value
End Set
End Property
Public Property Compression() As Integer
Get
Return oCompression
End Get
Set(ByVal value As Integer)
oCompression = value
End Set
End Property
Public Property KeyboardHook() As Integer
Get
Return oKeyboardHook
End Get
Set(ByVal value As Integer)
oKeyboardHook = value
End Set
End Property
Public Property AudioMode() As Integer
Get
Return oAudioMode
End Get
Set(ByVal value As Integer)
oAudioMode = value
End Set
End Property
Public Property RedirectPrinters() As Integer
Get
Return oRedirectPrinters
End Get
Set(ByVal value As Integer)
oRedirectPrinters = value
End Set
End Property
Public Property RedirectComPorts() As Integer
Get
Return oRedirectComPorts
End Get
Set(ByVal value As Integer)
oRedirectComPorts = value
End Set
End Property
Public Property RedirectSmartCards() As Integer
Get
Return oRedirectSmartCards
End Get
Set(ByVal value As Integer)
oRedirectSmartCards = value
End Set
End Property
Public Property RedirectClipBoard() As Integer
Get
Return oRedirectClipBoard
End Get
Set(ByVal value As Integer)
oRedirectClipBoard = value
End Set
End Property
Public Property RedirectPosDevices() As Integer
Get
Return oRedirectPosDevices
End Get
Set(ByVal value As Integer)
oRedirectPosDevices = value
End Set
End Property
Public Property DriveStoreDirect() As String
Get
Return oDriveStoreDirect
End Get
Set(ByVal value As String)
oDriveStoreDirect = value
End Set
End Property
Public Property DisplayConnectionBar() As Integer
Get
Return oDisplayConnectionBar
End Get
Set(ByVal value As Integer)
oDisplayConnectionBar = value
End Set
End Property
Public Property AutoReconnection() As Integer
Get
Return oAutoReconnection
End Get
Set(ByVal value As Integer)
oAutoReconnection = value
End Set
End Property
Public Property AuthenticationLevel() As Integer
Get
Return oAuthenticationLevel
End Get
Set(ByVal value As Integer)
oAuthenticationLevel = value
End Set
End Property
Public Property PromptForCredentials() As Integer
Get
Return oPromptForCredentials
End Get
Set(ByVal value As Integer)
oPromptForCredentials = value
End Set
End Property
Public Property NegotiateSecurityLayer() As Integer
Get
Return oNegotiateSecurityLayer
End Get
Set(ByVal value As Integer)
oNegotiateSecurityLayer = value
End Set
End Property
Public Property UserName() As String
Get
Return oUsername
End Get
Set(ByVal value As String)
oUsername = value
End Set
End Property
Public Property Domain() As String
Get
Return oDomain
End Get
Set(ByVal value As String)
oDomain = value
End Set
End Property
Public Property RemoteApplicationMode() As Integer
Get
Return oRemoteApplicationMode
End Get
Set(ByVal value As Integer)
oRemoteApplicationMode = value
End Set
End Property
Public Property AlternateShell() As String
Get
Return oAlternateShell
End Get
Set(ByVal value As String)
oAlternateShell = value
End Set
End Property
Public Property ShellWorkingDirectory() As String
Get
Return oShellWorkingDirectory
End Get
Set(ByVal value As String)
oShellWorkingDirectory = value
End Set
End Property
Public Property DisableWallpaper() As Integer
Get
Return oDisableWallpaper
End Get
Set(ByVal value As Integer)
oDisableWallpaper = value
End Set
End Property
Public Property DisableFullWindowDrag()
Get
Return oDisableFullWindowDrag
End Get
Set(ByVal value)
oDisableFullWindowDrag = value
End Set
End Property
Public Property AllowDesktopComposition() As Integer
Get
Return oAllowDesktopComposition
End Get
Set(ByVal value As Integer)
oAllowDesktopComposition = value
End Set
End Property
Public Property AllowFontSmoothing() As Integer
Get
Return oAllowFontSmoothing
End Get
Set(ByVal value As Integer)
oAllowFontSmoothing = value
End Set
End Property
Public Property DisableMenuAnims() As Integer
Get
Return oDisableMenuAnims
End Get
Set(ByVal value As Integer)
oDisableMenuAnims = value
End Set
End Property
Public Property DisableThemes() As Integer
Get
Return oDisableThemes
End Get
Set(ByVal value As Integer)
oDisableThemes = value
End Set
End Property
Public Property DisableCursorSettings() As Integer
Get
Return oDisableCursorSettings
End Get
Set(ByVal value As Integer)
oDisableCursorSettings = value
End Set
End Property
Public Property BitMapCachePersistEnable() As Integer
Get
Return oBitMapCachePersistEnable
End Get
Set(ByVal value As Integer)
oBitMapCachePersistEnable = value
End Set
End Property
Public Property GatewayHostName() As String
Get
Return oGatewayHostName
End Get
Set(ByVal value As String)
oGatewayHostName = value
End Set
End Property
Public Property GatewayUsageMethod() As Integer
Get
Return oGateWayUsageMethod
End Get
Set(ByVal value As Integer)
oGateWayUsageMethod = value
End Set
End Property
Public Property GatewayCredentialSource() As Integer
Get
Return oGateWayCredentialSource
End Get
Set(ByVal value As Integer)
oGateWayCredentialSource = value
End Set
End Property
Public Property GateWayProfileUsageMethod() As Integer
Get
Return oGateWayProfileUsageMethod
End Get
Set(ByVal value As Integer)
oGateWayProfileUsageMethod = value
End Set
End Property
#End Region
#Region "Subs"
Public Sub New()
'do nothing
End Sub
Public Sub New(ByVal SubKeyName As String)
Dim reg As New Reg
Me.Guid = SubKeyName.Substring(SubKeyName.LastIndexOf("\") + 1)
reg.ReadValue(reg.HKLM, SubKeyName, "objName", Me.Name)
Me.Text = Me.Name 'Needed for inheritance from treenode
reg.ReadValue(reg.HKLM, SubKeyName, "UseLocalCursor", Me.UseLocalCursor)
reg.ReadValue(reg.HKLM, SubKeyName, "LastConnect", Me.LastConnect)
reg.ReadValue(reg.HKLM, SubKeyName, "PrefCon", Me.PrefCon)
reg.ReadValue(reg.HKLM, SubKeyName, "TimesConnected", Me.TimesConnected)
reg.ReadValue(reg.HKLM, SubKeyName, "UseDesktopResize", Me.UseDesktopResize)
reg.ReadValue(reg.HKLM, SubKeyName, "FullScreen", Me.FullScreen)
reg.ReadValue(reg.HKLM, SubKeyName, "FullColour", Me.FullColour)
reg.ReadValue(reg.HKLM, SubKeyName, "LowColourLevel", Me.LowColourLevel)
reg.ReadValue(reg.HKLM, SubKeyName, "PreferredEncoding", Me.PreferredEncoding)
reg.ReadValue(reg.HKLM, SubKeyName, "AutoSelect", Me.AutoSelect)
reg.ReadValue(reg.HKLM, SubKeyName, "SharedVal", Me.SharedVal)
reg.ReadValue(reg.HKLM, SubKeyName, "SendPtrEvents", Me.SendPtrEvents)
reg.ReadValue(reg.HKLM, SubKeyName, "SendKeyEvents", Me.SendKeyEvents)
reg.ReadValue(reg.HKLM, SubKeyName, "SendCutText", Me.SendCutText)
reg.ReadValue(reg.HKLM, SubKeyName, "AcceptCutText", Me.AcceptCutText)
reg.ReadValue(reg.HKLM, SubKeyName, "DisableWinKeys", Me.DisableWinKeys)
reg.ReadValue(reg.HKLM, SubKeyName, "Emulate3", Me.Emulate3)
reg.ReadValue(reg.HKLM, SubKeyName, "PointerEventInterval", Me.PointerEventInterval)
reg.ReadValue(reg.HKLM, SubKeyName, "Monitor", Me.Monitor)
reg.ReadValue(reg.HKLM, SubKeyName, "MenuKey", Me.MenuKey)
reg.ReadValue(reg.HKLM, SubKeyName, "AutoReconnect", Me.AutoReconnect)
reg.ReadValue(reg.HKLM, SubKeyName, "AllowDesktopComposition", Me.AllowDesktopComposition)
reg.ReadValue(reg.HKLM, SubKeyName, "AllowFontSmoothing", Me.AllowFontSmoothing)
reg.ReadValue(reg.HKLM, SubKeyName, "AlternateShell", Me.AlternateShell)
reg.ReadValue(reg.HKLM, SubKeyName, "AudioMode", Me.AudioMode)
reg.ReadValue(reg.HKLM, SubKeyName, "AuthenticationLevel", Me.AuthenticationLevel)
reg.ReadValue(reg.HKLM, SubKeyName, "AutoReconnection", Me.AutoReconnection)
reg.ReadValue(reg.HKLM, SubKeyName, "BitMapCachePersistEnable", Me.BitMapCachePersistEnable)
reg.ReadValue(reg.HKLM, SubKeyName, "Compression", Me.Compression)
reg.ReadValue(reg.HKLM, SubKeyName, "DesktopHeight", Me.DesktopHeight)
reg.ReadValue(reg.HKLM, SubKeyName, "DesktopWidth", Me.DesktopWidth)
reg.ReadValue(reg.HKLM, SubKeyName, "DisableCursorSettings", Me.DisableCursorSettings)
reg.ReadValue(reg.HKLM, SubKeyName, "DisableFullWindowDrag", Me.DisableFullWindowDrag)
reg.ReadValue(reg.HKLM, SubKeyName, "DisableMenuAnims", Me.DisableMenuAnims)
reg.ReadValue(reg.HKLM, SubKeyName, "DisableWallpaper", Me.DisableWallpaper)
reg.ReadValue(reg.HKLM, SubKeyName, "DisplayConnectionBar", Me.DisplayConnectionBar)
reg.ReadValue(reg.HKLM, SubKeyName, "Domain", Me.Domain)
reg.ReadValue(reg.HKLM, SubKeyName, "DriveStoreDirect", Me.DriveStoreDirect)
reg.ReadValue(reg.HKLM, SubKeyName, "FullAddress", Me.FullAddress)
reg.ReadValue(reg.HKLM, SubKeyName, "GatewayCredentialSource", Me.GatewayCredentialSource)
reg.ReadValue(reg.HKLM, SubKeyName, "GatewayHostName", Me.GatewayHostName)
reg.ReadValue(reg.HKLM, SubKeyName, "GateWayProfileUsageMethod", Me.GateWayProfileUsageMethod)
reg.ReadValue(reg.HKLM, SubKeyName, "GatewayUsageMethod", Me.GatewayUsageMethod)
reg.ReadValue(reg.HKLM, SubKeyName, "KeyboardHook", Me.KeyboardHook)
reg.ReadValue(reg.HKLM, SubKeyName, "NegotiateSecurityLayer", Me.NegotiateSecurityLayer)
reg.ReadValue(reg.HKLM, SubKeyName, "PromptForCredentials", Me.PromptForCredentials)
reg.ReadValue(reg.HKLM, SubKeyName, "RedirectClipBoard", Me.RedirectClipBoard)
reg.ReadValue(reg.HKLM, SubKeyName, "RedirectComPorts", Me.RedirectComPorts)
reg.ReadValue(reg.HKLM, SubKeyName, "RedirectPosDevices", Me.RedirectPosDevices)
reg.ReadValue(reg.HKLM, SubKeyName, "RedirectPrinters", Me.RedirectPrinters)
reg.ReadValue(reg.HKLM, SubKeyName, "RedirectSmartCards", Me.RedirectSmartCards)
reg.ReadValue(reg.HKLM, SubKeyName, "RemoteApplicationMode", Me.RemoteApplicationMode)
reg.ReadValue(reg.HKLM, SubKeyName, "ScreenMode", Me.ScreenMode)
reg.ReadValue(reg.HKLM, SubKeyName, "SessionBPP", Me.SessionBPP)
reg.ReadValue(reg.HKLM, SubKeyName, "ShellWorkingDirectory", Me.ShellWorkingDirectory)
reg.ReadValue(reg.HKLM, SubKeyName, "UserName", Me.UserName)
reg.ReadValue(reg.HKLM, SubKeyName, "WinPosStr", Me.WinPosStr)
End Sub 'From Registry
Public Sub FillFromVNC(ByVal f As FileInfo)
'Read all the lines from the VNC File and put them into a string array.
Dim a As String() = File.ReadAllLines(f.FullName)
'Run a loop on the string array that we just created
Dim lc As Integer = 0
Do Until lc = a.Length
Dim str As String = a(lc)
'Since the VNC file contains header sections as in [options], the
'If str.contains("=") is needed to make the following str.indexof("=")
'work correctly for reading in the options.
If str.Contains("=") Then
'A Select statement is run on the lines to get each option and put
'the data into our collection object.
Select Case str.Remove(str.IndexOf("="))
Case "Host"
Me.FullAddress = str.Substring(str.LastIndexOf("=") + 1)
Case "UseLocalCursor"
Me.UseLocalCursor = str.Substring(str.LastIndexOf("=") + 1)
Case "UseDesktopResize"
Me.UseDesktopResize = str.Substring(str.LastIndexOf("=") + 1)
Case "FullScreen"
Me.FullScreen = str.Substring(str.LastIndexOf("=") + 1)
Case "FullColour"
Me.FullColour = str.Substring(str.LastIndexOf("=") + 1)
'...
Case "LowColourLevel"
Me.LowColourLevel = str.Substring(str.LastIndexOf("=") + 1)
Case "PreferredEncoding"
Me.PreferredEncoding = str.Substring(str.LastIndexOf("=") + 1)
Case "AutoSelect"
Me.AutoSelect = str.Substring(str.LastIndexOf("=") + 1)
Case "Shared"
Me.SharedVal = str.Substring(str.LastIndexOf("=") + 1)
Case "SendPtrEvents"
Me.SendPtrEvents = str.Substring(str.LastIndexOf("=") + 1)
Case "SendKeyEvents"
Me.SendKeyEvents = str.Substring(str.LastIndexOf("=") + 1)
Case "SendCutText"
Me.SendCutText = str.Substring(str.LastIndexOf("=") + 1)
Case "AcceptCutText"
Me.AcceptCutText = str.Substring(str.LastIndexOf("=") + 1)
Case "DisableWinKeys"
Me.DisableWinKeys = str.Substring(str.LastIndexOf("=") + 1)
Case "Emulate3"
Me.Emulate3 = str.Substring(str.LastIndexOf("=") + 1)
Case "PointerEventInterval"
Me.PointerEventInterval = str.Substring(str.LastIndexOf("=") + 1)
Case "Monitor"
Me.Monitor = str.Substring(str.LastIndexOf("=") + 1)
Case "MenuKey"
Me.MenuKey = str.Substring(str.LastIndexOf("=") + 1)
Case "AutoReconnect"
Me.AutoReconnect = str.Substring(str.LastIndexOf("=") + 1)
Case Else
End Select
End If
Me.PrefCon = 1 'Set preferred connection to 1 for VNC.
lc = lc + 1
Loop
End Sub
Public Sub FillFromRDP(ByVal f As FileInfo)
'FillFromRDP works very much the same as the VNC function of the same
'name with a couple small differences. Since the RDP file does not
'contain header sections, the line qualifier statement if str.contains("=")
'from the VNC function is not needed and the characters separating the
'parameters are different, in this case, the : character is used.
Dim a As String() = File.ReadAllLines(f.FullName)
Dim lc As Integer = 0
Do Until lc = a.Length
Dim str As String = a(lc)
Select Case str.Remove(str.IndexOf(":"))
Case "screen mode id"
Me.ScreenMode = str.Substring(str.LastIndexOf(":") + 1)
Case "desktopwidth"
Me.DesktopWidth = str.Substring(str.LastIndexOf(":") + 1)
Case "desktopheight"
Me.DesktopHeight = str.Substring(str.LastIndexOf(":") + 1)
Case "session bpp"
Me.SessionBPP = str.Substring(str.LastIndexOf(":") + 1)
Case "winposstr"
Me.WinPosStr = str.Substring(str.LastIndexOf(":") + 1)
Case "full address"
Me.FullAddress = str.Substring(str.LastIndexOf(":") + 1)
Case "compression"
Me.Compression = str.Substring(str.LastIndexOf(":") + 1)
Case "keyboardhook"
Me.KeyboardHook = str.Substring(str.LastIndexOf(":") + 1)
Case "audiomode"
Me.AudioMode = str.Substring(str.LastIndexOf(":") + 1)
Case "redirectprinters"
Me.RedirectPrinters = str.Substring(str.LastIndexOf(":") + 1)
Case "redirectcomports"
Me.RedirectComPorts = str.Substring(str.LastIndexOf(":") + 1)
Case "redirectsmartcards"
Me.RedirectSmartCards = str.Substring(str.LastIndexOf(":") + 1)
Case "redirectclipboard"
Me.RedirectClipBoard = str.Substring(str.LastIndexOf(":") + 1)
Case "redirectposdevices"
Me.RedirectPosDevices = str.Substring(str.LastIndexOf(":") + 1)
Case "drivestoredirect"
Me.DriveStoreDirect = str.Substring(str.LastIndexOf(":") + 1)
Case "displayconnectionbar"
Me.DisplayConnectionBar = str.Substring(str.LastIndexOf(":") + 1)
Case "autoreconnection enabled"
Me.AutoReconnection = str.Substring(str.LastIndexOf(":") + 1)
Case "authentication level"
Me.AuthenticationLevel = str.Substring(str.LastIndexOf(":") + 1)
Case "prompt for credentials"
Me.PromptForCredentials = str.Substring(str.LastIndexOf(":") + 1)
Case "negotiate security layer"
Me.NegotiateSecurityLayer = str.Substring(str.LastIndexOf(":") + 1)
Case "username"
Me.UserName = str.Substring(str.LastIndexOf(":") + 1)
Case "domain"
Me.Domain = str.Substring(str.LastIndexOf(":") + 1)
Case "remoteapplicationmode"
Me.RemoteApplicationMode = str.Substring(str.LastIndexOf(":") + 1)
Case "alternate shell"
Me.AlternateShell = str.Substring(str.LastIndexOf(":") + 1)
Case "shell working directory"
Me.ShellWorkingDirectory = str.Substring(str.LastIndexOf(":") + 1)
Case "disable wallpaper"
Me.DisableWallpaper = str.Substring(str.LastIndexOf(":") + 1)
Case "disable full window drag"
Me.DisableFullWindowDrag = str.Substring(str.LastIndexOf(":") + 1)
Case "allow desktop composition"
Me.AllowDesktopComposition = str.Substring(str.LastIndexOf(":") + 1)
Case "allow font smoothing"
Me.AllowFontSmoothing = str.Substring(str.LastIndexOf(":") + 1)
Case "disable menu anims"
Me.DisableMenuAnims = str.Substring(str.LastIndexOf(":") + 1)
Case "disable themes"
Me.DisableThemes = str.Substring(str.LastIndexOf(":") + 1)
Case "disable cursor setting"
Me.DisableCursorSettings = str.Substring(str.LastIndexOf(":") + 1)
Case "bitmapcachepersistenable"
Me.BitMapCachePersistEnable = str.Substring(str.LastIndexOf(":") + 1)
Case "gatewayhostname"
Me.GatewayHostName = str.Substring(str.LastIndexOf(":") + 1)
Case "gatewayusagemethod"
Me.GatewayUsageMethod = str.Substring(str.LastIndexOf(":") + 1)
Case "gatewaycredentialssource"
Me.GatewayCredentialSource = str.Substring(str.LastIndexOf(":") + 1)
Case "gatewayprofileusagemethod"
Me.GateWayProfileUsageMethod = str.Substring(str.LastIndexOf(":") + 1)
End Select
Me.PrefCon = 0 'Set preferred connection type to 0 for RDP.
lc = lc + 1
Loop
End Sub 'From File
#End Region
#Region "Methods"
Public Function Copy(ByVal c As Connection) As Connection
c.AcceptCutText = Me.AcceptCutText
c.AllowDesktopComposition = Me.AllowDesktopComposition
c.AllowFontSmoothing = Me.AllowFontSmoothing
c.AlternateShell = Me.AlternateShell
c.AudioMode = Me.AudioMode
c.AuthenticationLevel = Me.AuthenticationLevel
c.AutoReconnect = Me.AutoReconnect
c.AutoReconnection = Me.AutoReconnection
c.AutoSelect = Me.AutoSelect
c.BitMapCachePersistEnable = Me.BitMapCachePersistEnable
c.Compression = Me.Compression
c.DesktopHeight = Me.DesktopHeight
c.DesktopWidth = Me.DesktopWidth
c.DisableCursorSettings = Me.DisableCursorSettings
c.DisableMenuAnims = Me.DisableMenuAnims
c.DisableThemes = Me.DisableThemes
c.DisableWallpaper = Me.DisableWallpaper
c.DisableWinKeys = Me.DisableWinKeys
c.DisplayConnectionBar = Me.DisplayConnectionBar
c.Domain = Me.Domain
c.DriveStoreDirect = Me.DriveStoreDirect
c.Emulate3 = Me.Emulate3
c.FullAddress = Me.FullAddress
c.FullColour = Me.FullColour
c.FullScreen = Me.FullScreen
c.GatewayCredentialSource = Me.GatewayCredentialSource
c.GatewayHostName = Me.GatewayHostName
c.GateWayProfileUsageMethod = Me.GateWayProfileUsageMethod
c.GatewayUsageMethod = Me.GatewayUsageMethod
c.KeyboardHook = Me.KeyboardHook
c.LowColourLevel = Me.LowColourLevel
c.MenuKey = Me.MenuKey
c.Monitor = Me.Monitor
c.Name = Me.Name
c.NegotiateSecurityLayer = Me.NegotiateSecurityLayer
c.PointerEventInterval = Me.PointerEventInterval
c.PreferredEncoding = Me.PreferredEncoding
c.PromptForCredentials = Me.PromptForCredentials
c.RedirectClipBoard = Me.RedirectClipBoard
c.RedirectComPorts = Me.RedirectComPorts
c.RedirectPosDevices = Me.RedirectPosDevices
c.RedirectPrinters = Me.RedirectPrinters
c.RedirectSmartCards = Me.RedirectSmartCards
c.RemoteApplicationMode = Me.RemoteApplicationMode
c.ScreenMode = Me.ScreenMode
c.SendCutText = Me.SendCutText
c.SendKeyEvents = Me.SendKeyEvents
c.SendPtrEvents = Me.SendPtrEvents
c.SessionBPP = Me.SessionBPP
c.SharedVal = Me.SharedVal
c.ShellWorkingDirectory = Me.ShellWorkingDirectory
c.UseDesktopResize = Me.UseDesktopResize
c.UseLocalCursor = Me.UseLocalCursor
c.UserName = Me.UserName
c.WinPosStr = Me.WinPosStr
c.PrefCon = Me.PrefCon
Return c
End Function
Public Function CreateRDPFile() As FileInfo
'This section of code creates an RDP File based on the
'.RDP File Format that the RDP Connector drops out when
'it is asked to save a connection. Note that this format
'is different from the VNC file format.
'RDP Options are entered into the .RDP file like the following:
'option:variable type:parameter
Dim lines As String() = { _
"screen mode id:i:" & Me.ScreenMode, _
"desktopwidth:i:" & Me.DesktopWidth, _
"desktopheight:i:" & Me.DesktopHeight, _
"session bpp:i:" & Me.SessionBPP, _
"winposstr:s:" & Me.WinPosStr, _
"full address:s:" & Me.FullAddress, _
"compression:i:" & Me.Compression, _
"keyboardhook:i:" & Me.KeyboardHook, _
"audiomode:i:" & Me.AudioMode, _
"redirectprinters:i:" & Me.RedirectPrinters, _
"redirectcomports:i:" & Me.RedirectComPorts, _
"redirectsmartcards:i:" & Me.RedirectSmartCards, _
"redirectclipboard:i:" & Me.RedirectClipBoard, _
"redirectposdevices:i:" & Me.RedirectPosDevices, _
"drivestoredirect:s:" & Me.DriveStoreDirect, _
"displayconnectionbar:i:" & Me.DisplayConnectionBar, _
"autoreconnection enabled:i:" & Me.AutoReconnection, _
"authentication level:i:" & Me.AuthenticationLevel, _
"prompt for credentials:i:" & Me.PromptForCredentials, _
"negotiate security layer:i:" & Me.NegotiateSecurityLayer, _
"username:s:" & Me.UserName, _
"domain:s:" & Me.Domain, _
"remoteapplicationmode:i:" & Me.RemoteApplicationMode, _
"alternate shell:s:" & Me.AlternateShell, _
"shell working directory:s:" & Me.ShellWorkingDirectory, _
"disable wallpaper:i:" & Me.DisableWallpaper, _
"disable full window drag:i:" & Me.DisableFullWindowDrag, _
"allow desktop composition:i:" & Me.AllowDesktopComposition, _
"allow font smoothing:i:" & Me.AllowFontSmoothing, _
"disable menu anims:i:" & Me.DisableMenuAnims, _
"disable themes:i:" & Me.DisableThemes, _
"disable cursor setting:i:" & Me.DisableCursorSettings, _
"bitmapcachepersistenable:i:" & Me.BitMapCachePersistEnable, _
"gatewayhostname:s:" & Me.GatewayHostName, _
"gatewayusagemethod:i:" & Me.GatewayUsageMethod, _
"gatewaycredentialssource:i" & Me.GatewayCredentialSource, _
"gatewayprofileusagemethod:i:" & Me.GateWayProfileUsageMethod _
}
'Create a new .vnc file in the startup path of the application.
Dim path As String = Application.StartupPath & "\~" & Me.Name & ".rdp"
Try
File.WriteAllLines(path, lines)
Catch ex As Exception
MsgBox("Cannot write to RDP File")
End Try
Dim f As FileInfo = New FileInfo(path)
Return f
End Function
Public Function CreateVNCFile() As FileInfo
'This section of code creates a VNC File based on the
'.VNC File Format that the VNC Viewer drops out when
'it is asked to save a connection. Note that this format
'is different from the RDP file format.
'VNC Options are entered into the .vnc file like the following:
'option=parameter
'two header sections exist within the files, [Connection] and
'[Options], RDPMan mimics these lines in this method.
Dim lines As String() = { _
"[Connection]", _
"Host=" & Me.FullAddress, _
"[Options]", _
"UseLocalCursor=" & Me.UseLocalCursor, _
"UseDesktopResize=" & Me.UseDesktopResize, _
"FullScreen=" & Me.FullScreen, _
"FullColour=" & Me.FullColour, _
"LowColourLevel=" & Me.LowColourLevel, _
"PreferredEncoding=" & Me.PreferredEncoding, _
"AutoSelect=" & Me.AutoSelect, _
"Shared=" & Me.SharedVal, _
"SendPtrEvents=" & Me.SendPtrEvents, _
"SendKeyEvents=" & Me.SendKeyEvents, _
"SendCutText=" & Me.SendCutText, _
"AcceptCutText=" & Me.AcceptCutText, _
"DisableWinKeys=" & Me.DisableWinKeys, _
"Emulate3=" & Me.Emulate3, _
"PointerEventInterval=" & Me.PointerEventInterval, _
"Monitor=" & Me.Monitor, _
"MenuKey=" & Me.MenuKey, _
"AutoReconnect=" & Me.AutoReconnect _
}
'Create a new .vnc file in the startup path of the application.
Dim path As String = Application.StartupPath & "\~" & Me.Name & ".vnc"
Try
File.WriteAllLines(path, lines)
Catch ex As Exception
MsgBox("Cannot write to VNC File")
End Try
Dim f As FileInfo = New FileInfo(path)
Return f
End Function
Public Sub SaveToReg()
'create a registry object from the registry class in
'registry.vb to access the registry
Dim reg As New Reg
Dim key As String
'Check to see if the connection objects guid = nothing.
'If it is, create a new guid. This is done so that each
'connection object gets its own unique registry subkey.
If Me.Guid Is Nothing Then
Me.Guid = System.Guid.NewGuid.ToString
key = "Software\RDPMan\" & Me.Guid & "\"
reg.CreateSubKey(reg.HKLM, Name)
Else
key = "Software\RDPMan\" & Me.Guid & "\"
End If
'Write values to the registry
If Me.Guid.Contains("Default") Then
reg.WriteValue(reg.HKLM, key, "ObjName", "(Default)")
Else
reg.WriteValue(reg.HKLM, key, "ObjName", Me.Name)
reg.WriteValue(reg.HKLM, key, "FullAddress", Me.FullAddress)
End If
reg.WriteValue(reg.HKLM, key, "PrefCon", Me.PrefCon)
reg.WriteValue(reg.HKLM, key, "TimesConnected", Me.TimesConnected)
reg.WriteValue(reg.HKLM, key, "LastConnect", Me.LastConnect)
reg.WriteValue(reg.HKLM, key, "UseLocalCursor", Me.UseLocalCursor)
reg.WriteValue(reg.HKLM, key, "UseDesktopResize", Me.UseDesktopResize)
reg.WriteValue(reg.HKLM, key, "FullScreen", Me.FullScreen)
reg.WriteValue(reg.HKLM, key, "FullColour", Me.FullColour)
reg.WriteValue(reg.HKLM, key, "LowColourLevel", Me.LowColourLevel)
reg.WriteValue(reg.HKLM, key, "PreferredEncoding", Me.PreferredEncoding)
reg.WriteValue(reg.HKLM, key, "AutoSelect", Me.AutoSelect)
reg.WriteValue(reg.HKLM, key, "Shared", Me.SharedVal)
reg.WriteValue(reg.HKLM, key, "SendPtrEvents", Me.SendPtrEvents)
reg.WriteValue(reg.HKLM, key, "SendKeyEvents", Me.SendKeyEvents)
reg.WriteValue(reg.HKLM, key, "SendCutText", Me.SendCutText)
reg.WriteValue(reg.HKLM, key, "AcceptCutText", Me.AcceptCutText)
reg.WriteValue(reg.HKLM, key, "DisableWinKeys", Me.DisableWinKeys)
reg.WriteValue(reg.HKLM, key, "Emulate3", Me.Emulate3)
reg.WriteValue(reg.HKLM, key, "PointerEventInterval", Me.PointerEventInterval)
reg.WriteValue(reg.HKLM, key, "Monitor", Me.Monitor)
reg.WriteValue(reg.HKLM, key, "MenuKey", Me.MenuKey)
reg.WriteValue(reg.HKLM, key, "AutoReconnect", Me.AutoReconnect)
reg.WriteValue(reg.HKLM, key, "AllowDesktopComposition", Me.AllowDesktopComposition)
reg.WriteValue(reg.HKLM, key, "AllowFontSmoothing", Me.AllowFontSmoothing)
reg.WriteValue(reg.HKLM, key, "AlternateShell", Me.AlternateShell)
reg.WriteValue(reg.HKLM, key, "AudioMode", Me.AudioMode)
reg.WriteValue(reg.HKLM, key, "AuthenticationLevel", Me.AuthenticationLevel)
reg.WriteValue(reg.HKLM, key, "AutoReconnection", Me.AutoReconnection)
reg.WriteValue(reg.HKLM, key, "BitMapCachePersistEnable", Me.BitMapCachePersistEnable)
reg.WriteValue(reg.HKLM, key, "Compression", Me.Compression)
reg.WriteValue(reg.HKLM, key, "DesktopHeight", Me.DesktopHeight)
reg.WriteValue(reg.HKLM, key, "DesktopWidth", Me.DesktopWidth)
reg.WriteValue(reg.HKLM, key, "DisableCursorSettings", Me.DisableCursorSettings)
reg.WriteValue(reg.HKLM, key, "DisableFullWindowDrag", Me.DisableFullWindowDrag)
reg.WriteValue(reg.HKLM, key, "DisableMenuAnims", Me.DisableMenuAnims)
reg.WriteValue(reg.HKLM, key, "DisableWallpaper", Me.DisableWallpaper)
reg.WriteValue(reg.HKLM, key, "DisplayConnectionBar", Me.DisplayConnectionBar)
reg.WriteValue(reg.HKLM, key, "Domain", Me.Domain)
reg.WriteValue(reg.HKLM, key, "DriveStoreDirect", Me.DriveStoreDirect)
reg.WriteValue(reg.HKLM, key, "GatewayCredentialSource", Me.GatewayCredentialSource)
reg.WriteValue(reg.HKLM, key, "GatewayHostName", Me.GatewayHostName)
reg.WriteValue(reg.HKLM, key, "GateWayProfileUsageMethod", Me.GateWayProfileUsageMethod)
reg.WriteValue(reg.HKLM, key, "GatewayUsageMethod", Me.GatewayUsageMethod)
reg.WriteValue(reg.HKLM, key, "KeyboardHook", Me.KeyboardHook)
reg.WriteValue(reg.HKLM, key, "NegotiateSecurityLayer", Me.NegotiateSecurityLayer)
reg.WriteValue(reg.HKLM, key, "PromptForCredentials", Me.PromptForCredentials)
reg.WriteValue(reg.HKLM, key, "RedirectClipBoard", Me.RedirectClipBoard)
reg.WriteValue(reg.HKLM, key, "RedirectComPorts", Me.RedirectComPorts)
reg.WriteValue(reg.HKLM, key, "RedirectPosDevices", Me.RedirectPosDevices)
reg.WriteValue(reg.HKLM, key, "RedirectPrinters", Me.RedirectPrinters)
reg.WriteValue(reg.HKLM, key, "RedirectSmartCards", Me.RedirectSmartCards)
reg.WriteValue(reg.HKLM, key, "RemoteApplicationMode", Me.RemoteApplicationMode)
reg.WriteValue(reg.HKLM, key, "ScreenMode", Me.ScreenMode)
reg.WriteValue(reg.HKLM, key, "SessionBPP", Me.SessionBPP)
reg.WriteValue(reg.HKLM, key, "ShellWorkingDirectory", Me.ShellWorkingDirectory)
reg.WriteValue(reg.HKLM, key, "UserName", Me.UserName)
reg.WriteValue(reg.HKLM, key, "WinPosStr", Me.WinPosStr)
End Sub
Private Sub IncrementConnect()
Dim reg As New Reg
Dim key As String = "Software\RDPMan\" & Me.Guid & "\"
reg.WriteValue(reg.HKLM, key, "TimesConnected", Me.TimesConnected + 1)
reg.WriteValue(reg.HKLM, key, "LastConnect", System.DateTime.Now.ToString())
End Sub
Public Sub DeleteFromReg()
Dim reg As New Reg
'Since the registry keys for each Connection object
'are created based on a GUID created in the SaveToReg
'function, the DeleteSubKeyTree from the registry.vb
'file included with this app can be run on the me.guid
'property.
reg.AppReg.DeleteSubKeyTree(Me.Guid)
End Sub
Public Function ConnectRDP() As FileInfo
'Runs the CreateRDPFile Method and attempts to fun
'the RDP file. This run is using the command
'system.diagnostics.Process.start on the filename.
'since the mstsc.exe application itself is not mentioned
'here, the file will be run based on the .rdp file association.
Dim f As FileInfo = Me.CreateRDPFile
Try
Process.Start(f.FullName)
Me.IncrementConnect()
Catch ex As Exception
Throw
End Try
Return f
End Function
Public Sub ConnectTelnet()
'The intellisense for the process start command
'notes that the second argument is something like
'the username that one wants the application to run as
'but I found out from someone's article that the
'function takes application parameters as the second
'parameter as well in an overload.
Try
Process.Start("telnet", Me.FullAddress)
Me.IncrementConnect()
Catch ex As Exception
Throw
End Try
End Sub
Public Function ConnectVNC() As FileInfo
Dim f As FileInfo = Me.CreateVNCFile
Try
Process.Start(f.FullName)
Me.IncrementConnect()
Catch ex As Exception
Throw
End Try
Return f
End Function
#End Region
End Class