@@ -119,9 +119,14 @@ Public Class RDPSign
119119
120120 End If
121121
122- 'If we get here, we should be good to run the command to sign the RDP file.
123- Dim Command As String = GetSysDir() & "\rdpsign.exe"
122+ 'If we get here, we should be good to run the command to sign the RDP file.
123+
124+ 'Grab the rdpsign.exe location and then verify that it exists
125+
126+ Dim Command = GetRdpsignExeLocation()
127+
124128 If My.Computer.FileSystem.FileExists(Command) Then
129+
125130 Dim Arguments As String
126131 Dim FileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Command)
127132 ' On my windows 10 computer, the argument is /sha256 instead of /sha1. /sha1 doesn't work.
@@ -147,6 +152,31 @@ Public Class RDPSign
147152
148153 End Sub
149154
155+ ''' <summary>
156+ ''' Find the full path to rdpsign.exe from a list of possible locations
157+ ''' </summary>
158+ ''' <returns>A path to rdpsign.exe or an empty string</returns>
159+ Function GetRdpsignExeLocation()
160+ 'Each path to check for rdpsign.exe is added to this array.
161+ 'If it is found in more than one location, the lowest in the list will be selected.
162+ Dim PossibleRdpsignPaths() As String = {
163+ GetSysDir(),
164+ My.Application.Info.DirectoryPath
165+ }
166+
167+ Dim FinalRdpSignPath As String = ""
168+
169+ For Each RdpsignPath In PossibleRdpsignPaths
170+ If My.Computer.FileSystem.FileExists(RdpsignPath & "\rdpsign.exe" ) Then
171+ FinalRdpSignPath = RdpsignPath & "\rdpsign.exe"
172+ End If
173+ Next
174+
175+ Return FinalRdpSignPath
176+
177+ End Function
178+
179+
150180 Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" ( ByVal lpBuffer As String , ByVal nSize As Long ) As Long
151181
152182 Function GetSysDir() As String
0 commit comments