Solved

WebBrowser, Prevent Telnet

Posted on 1998-11-07
7
225 Views
Last Modified: 2010-04-30
Useing the WebBrowser, how do you prevent it
from opening links like Telnet://Host.com

0
Comment
Question by:idcvbteam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Expert Comment

by:decypher
ID: 1443741
There are several ways this can be accomplished.  Some of the older browsers had the option to choose which program loaded when you used a specific protocol call (i.e. http://, ftp://, telnet://)  However the new ones don't seem to have this feature.  If you want to block this completely, you need to go into the registry (using regedit or regedt32), and modify
HKEY_CLASSES_ROOT/telnet/shell/open/command  and the Default value in the command section.  You will something like  "C:\windows\telnet.exe %1" for the value.  Single double click the Default, and remove the entry, or point it to some other program (i.e. maybe something that tells the user they cannot use this).  Any program will do.  And if it's just meant to run, don't put the %1 at the end of the value.  That's it! :)
Good Luck
decYPH3r

P.S. Registry editing can be dangerous.  Don't blame me if it messes up.  I take no responsibility.  (read microsofts speal) :)

0
 

Author Comment

by:idcvbteam
ID: 1443742

Sorry,
I really Intend on blocking it thre the Web Browser
Control. I do not wish to modify these settings as I hate
it when other apps do this to my system.

I simply would like to cancel any url that starts with
telnet://

So far, I can read it, just do not know how
to cancel it.

0
 

Expert Comment

by:decypher
ID: 1443743
Following is code that can be placed in the click event for the text box that houses the URL.  The code that tests for Telnet should be here, as well as anywhere else you are telling the Internet Browser Control to Navigate
(i.e. brwWebBrowser.Navigate).  It's a simple check of the string, to make sure that Telnet is not present).  You can modify the actual source to be as picky as you want.  You can also expand it so that users don't get unwanted PROTOCOL errors. I.e. if they type  asdf:// or whatever.  This works just fine, and displays a message to the user that Telnet is not allowed.  Any of this can be changed to suit your purposes.  It's simple easy and quick though, and catches the problem before it starts :)

decypher

------------------------------------

Private Sub cboAddress_Click()
    If mbDontNavigateNow Then Exit Sub
    timTimer.Enabled = True
    If UCase$(Left$(cboAddress.Text, 6)) = "TELNET" Then
      Msg = "Telnet Not Allowed"
      Style = vbOKOnly
      Title = "Sorry"
      Response = MsgBox(Msg, Style, Title)
    Else
        brwWebBrowser.Navigate cboAddress.Text
    End If
End Sub
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:idcvbteam
ID: 1443744

Sorry, but I need to prevent the WebBrowser from launching Telnet, not the user.

You see, the user can still click on Links that launch Telnet.
I want to stop that.
0
 

Accepted Solution

by:
decypher earned 30 total points
ID: 1443745
OK... You made me work for this one!  Here's the code you need to completely block Telnet, including Clicks in the browser!
You will find the Sub procedure as one included with the Browser control... just cute the code out from the middle, and your set to go!  Rename variables as necessary.

Private Sub brwWebBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

'Checks to see what type of URL they are going to
If UCase$(Left$(URL, 4)) = "HTTP" Then
 Exit Sub
ElseIf UCase$(Left$(URL, 3)) = "FTP" Then
 Exit Sub
ElseIf UCase$(Left$(URL, 6)) = "TELNET" Then
  'Lets them know Telnet Not Allowed
  Response = MsgBox("Telnet Not Allowed", vbOKOnly, "Sorry")
   If Response = vbOK Then
     'Cancels navigation to Telnet session
     Cancel = True
   End If
Else
  Exit Sub
End If

End Sub
0
 

Expert Comment

by:decypher
ID: 1443746
Shorter code to do the same thing, I just removed the calls to HTTP and FTP.  However, you can add functionality to your program by adding FTP or HTTP, or whatever valid URL's you want to this procedure, then on the last ELSE, Cancel it there, and have a message telling your users that they entered an Invalid URL, or something of the sort.  That way you are telling them a nice message, not the control sending back a nasty one.


'Checks to see what type of URL they are going to
If UCase$(Left$(URL, 6)) = "TELNET" Then
  'Lets them know Telnet Not Allowed
  Response = MsgBox("Telnet Not Allowed", vbOKOnly, "Sorry")
   If Response = vbOK Then
     'Cancels navigation to Telnet session
     Cancel = True
   End If
Else
  Exit Sub
End If
0
 

Author Comment

by:idcvbteam
ID: 1443747

Bingo!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question