vb.netsecurityinternet-explorertrusted-sites

Detect if a website is untrusted by IE?


I'm working on a web application in VB.net that requires a user to list the app's site as trusted in IE in order to use.

I know that programmatically adding itself to a user's trusted sites list is dangerous, and illogical, so I was trying to find out if it was possible to check the user's browser settings to see if a website is on their trusted sites list.

That way, if a user has not added the website to their list, I would be able to generate a popup that can show instructions on how to do so manually, or at least display a direct link to a separate webpage with instructions.


Solution

  • Of course I don't know your website so I used https://stackoverflow.com.

    If you add https://stackoverflow.com to your trusted sites you will get a entry named stackoverflow.com in your registry.
    The location is:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains

    So check if there is a entry named stackoverflow.com at that location.

    Imports Microsoft.Win32
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim currentUserRegistry As RegistryKey = Registry.CurrentUser
        Dim runRegistryKey As RegistryKey = currentUserRegistry.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\stackoverflow.com", True)
    
        If runRegistryKey IsNot Nothing Then
            MsgBox("Trusted")
        Else
            MsgBox("Not Trusted")
        End If
    End Sub