Advanced webbrowser control help needed

J

Jim Hubbard

I want to implement the same type of activeX restrictions in my browser
application that the new SP2 for XP places in Internet Explorer.

I have found 2 web pages dealing with this functionality
(http://msdn.microsoft.com/library/d...szone/reference/enums/INTERNETFEATURELIST.asp
and
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/wbcustomization.asp)
but I am at a loss as to how to implement this functionality in VB.Net or
C#.

I tried adding urlmon.dll to my VB.Net project as a reference to use the
CoInternetSetFeatureEnabled functionality (see
http://msdn.microsoft.com/library/d...nce/functions/cointernetsetfeatureenabled.asp),
but Visual Studio will not allow it. I get, in part, "This is not a valid
assembly or COM component." when I try and add it to my project.

Any help in implementing this type of functionality would be greatly
appreciated.

VB.Net is the language I am most familiar with, but C# examples would also
be helpful. I will re-write the app in C# if needed.
 
C

Charles Law

Hi Jim

Try the following

<code>
Public Enum INTERNETFEATURELIST
FEATURE_OBJECT_CACHING = 0
FEATURE_ZONE_ELEVATION = 1
FEATURE_MIME_HANDLING = 2
FEATURE_MIME_SNIFFING = 3
FEATURE_WINDOW_RESTRICTIONS = 4
FEATURE_WEBOC_POPUPMANAGEMENT = 5
FEATURE_BEHAVIORS = 6
FEATURE_DISABLE_MK_PROTOCOL = 7
FEATURE_LOCALMACHINE_LOCKDOWN = 8
FEATURE_SECURITYBAND = 9
FEATURE_RESTRICT_ACTIVEXINSTALL = 10
FEATURE_VALIDATE_NAVIGATE_URL = 11
FEATURE_RESTRICT_FILEDOWNLOAD = 12
FEATURE_ADDON_MANAGEMENT = 13
FEATURE_PROTOCOL_LOCKDOWN = 14
FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15
FEATURE_SAFE_BINDTOOBJECT = 16
FEATURE_UNC_SAVEDFILECHECK = 17
FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18
FEATURE_ENTRY_COUNT = 19
End Enum

<DllImport("urlmon.DLL")> _
Public Shared Function CoInternetSetFeatureEnabled(ByVal featureEntry As
INTERNETFEATURELIST, ByVal dwFlags As Integer, ByVal fEnable As Boolean) As
Integer
End Function

<DllImport("urlmon.DLL")> _
Public Shared Function CoInternetIsFeatureEnabled(ByVal featureEntry As
INTERNETFEATURELIST, ByVal dwFlags As Integer) As Integer
End Function

Private Sub SetFeatureEnabled()

Dim lr As Integer = 0

Dim featureToEnable As INTERNETFEATURELIST =
INTERNETFEATURELIST.FEATURE_WEBOC_POPUPMANAGEMENT

If CoInternetSetFeatureEnabled(featureToEnable,
SET_FEATURE_ON_PROCESS, True) = 0 Then
' Check to make sure that the API worked as expected
If CoInternetIsFeatureEnabled(featureToEnable,
SET_FEATURE_ON_PROCESS) <> 0 Then
lr = 2
End If
Else
' The API returned an error while enabling pop-up management
lr = 1
End If

End Sub
</code>

Calling SetFeatureEnabled runs without error, although I haven't attempted
to check whether the browser then behaves as you expect. It does, however,
load the page that I subsequently navigate to.

HTH

Charles
 
J

Jim Hubbard

Thanks for the help.

Charles Law said:
Hi Jim

Try the following

<code>
Public Enum INTERNETFEATURELIST
FEATURE_OBJECT_CACHING = 0
FEATURE_ZONE_ELEVATION = 1
FEATURE_MIME_HANDLING = 2
FEATURE_MIME_SNIFFING = 3
FEATURE_WINDOW_RESTRICTIONS = 4
FEATURE_WEBOC_POPUPMANAGEMENT = 5
FEATURE_BEHAVIORS = 6
FEATURE_DISABLE_MK_PROTOCOL = 7
FEATURE_LOCALMACHINE_LOCKDOWN = 8
FEATURE_SECURITYBAND = 9
FEATURE_RESTRICT_ACTIVEXINSTALL = 10
FEATURE_VALIDATE_NAVIGATE_URL = 11
FEATURE_RESTRICT_FILEDOWNLOAD = 12
FEATURE_ADDON_MANAGEMENT = 13
FEATURE_PROTOCOL_LOCKDOWN = 14
FEATURE_HTTP_USERNAME_PASSWORD_DISABLE = 15
FEATURE_SAFE_BINDTOOBJECT = 16
FEATURE_UNC_SAVEDFILECHECK = 17
FEATURE_GET_URL_DOM_FILEPATH_UNENCODED = 18
FEATURE_ENTRY_COUNT = 19
End Enum

<DllImport("urlmon.DLL")> _
Public Shared Function CoInternetSetFeatureEnabled(ByVal featureEntry
As INTERNETFEATURELIST, ByVal dwFlags As Integer, ByVal fEnable As
Boolean) As Integer
End Function

<DllImport("urlmon.DLL")> _
Public Shared Function CoInternetIsFeatureEnabled(ByVal featureEntry As
INTERNETFEATURELIST, ByVal dwFlags As Integer) As Integer
End Function

Private Sub SetFeatureEnabled()

Dim lr As Integer = 0

Dim featureToEnable As INTERNETFEATURELIST =
INTERNETFEATURELIST.FEATURE_WEBOC_POPUPMANAGEMENT

If CoInternetSetFeatureEnabled(featureToEnable,
SET_FEATURE_ON_PROCESS, True) = 0 Then
' Check to make sure that the API worked as expected
If CoInternetIsFeatureEnabled(featureToEnable,
SET_FEATURE_ON_PROCESS) <> 0 Then
lr = 2
End If
Else
' The API returned an error while enabling pop-up management
lr = 1
End If

End Sub
</code>

Calling SetFeatureEnabled runs without error, although I haven't attempted
to check whether the browser then behaves as you expect. It does, however,
load the page that I subsequently navigate to.

HTH

Charles
 
J

Jim Hubbard

Found that the Microsoft security model interferes with handling security
myself without allowing the granular control that I need for each URL.

I found a way that should work and am coding my own control (that uses the
webbrowser control also) to allow total control over the objects displayed
in the webbrowser control (whether they are vbscripts, java applets, activeX
controls, images or whatever).

Thanks again for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top