I am working within an Excel workbook that calls internet explorer and directs the workbook user to a log-in page in order to validate them and then retrieve data from our server. I have found that if users have 'Protected Mode' (Internet Options --> Security) enabled in IE they will often get "stuck" on the log-in page after entering their username and password. When 'Protected Mode' is disabled, there is no issue.
I am trying to create a macro that will detect their IE settings and notify the user if protected mode is enabled (and potentially change this setting for them with VBA using the PutProperty
method, if possible). I am currently working with Microsoft Internet Controls reference. The route I have attempted is below (within a subroutine, of course).
Dim objBrowser As InternetExplorer
Dim vProtected As Variant
Set objBrowser = New InternetExplorer
'Opens IE and navigates to log-in page
'The code here works as expected
'No idea what to put in for arguments in GetProperty
vProtected = objBrowser.GetProperty("?")
I am unsure of what data type GetProperty
actually returns (hence the variant) and I do not know what to pass in it for arguments. Additionally, if this is the wrong way entirely to do this I am open to a new course of action.
The MSDN article on the GetProperty method of the InternetExplorer object was less than helpful.
It is worth mentioning I am quite new to Microsoft Internet Controls and the InternetExplorer object, this is the first time I've worked with it.
Thank you for your time and consideration!
The solution ended up being vastly different than what I was going for. I have resigned myself to the fact that I must play with the registry in order to achieve the behavior I want. Though this was undesirable, here is what I ended up doing in VBA.
This is not my final code, as I am still working on the project, but it suffices.
Dim obj_Shell
Dim v_Result As Variant
'Variable to capture user response
Dim v_Response As Variant
Set obj_Shell = CreateObject("WScript.Shell")
'CHECK INTERNET EXPLORER PROTECTED MODE SETTINGS
'Reads the registry key that determines whether 'Protected Mode' is enabled in internet explorer for the 'Internet' security zone
'as opposed to 'Local intranet' or 'Trusted Sites', etc.
'The 3 in the registry key path refers to the zone 'Internet'.
Debug.Print "Checking user's Internet Explorer protected mode settings..."
v_Result = obj_Shell.RegRead _
("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500")
Select Case v_Result
Case 0 'Protected Mode is enabled
Debug.Print " Protected mode is enabled!"
v_Response = MsgBox("Protected mode is enabled in Internet Explorer. " & _
"This may cause issues with your submission. " & _
"Would you like to disable protected mode?", vbYesNo, "Protected Mode Enabled")
If v_Response = vbYes Then
obj_Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\2500", 3, "REG_DWORD"
MsgBox ("Protected mode has been disabled! Submission will not proceed.")
End If
Case 3 'Protected Mode is disabled
Debug.Print " Protected mode is disabled"
Case Else
Debug.Print "Unable to determine status of protected mode in IE"
Debug.Print v_Result
End Select
I don't think you can use GetProperty to read out the browsers' security settings. From the doc:
- GetProperty method: Gets the value associated with a user-defined property name.
- PutProperty method: Associates a user-defined name/value pair with the object.
You may want to explore the protected mode API described here, or the URL Security Zones API described here.