2013-12-17 29 views
0

我在調用Internet Explorer的Excel工作簿中工作,並將工作簿用戶指向登錄頁面以驗證它們,然後從我們的服務器檢索數據。我發現如果用戶在IE中啓用了「保護模式」(Internet選項 - >安全),他們通常會在輸入用戶名和密碼後在登錄頁面「卡住」。當「保護模式」被禁用時,沒有問題。使用VBA獲取或設置Internet Explorer選項

我試圖創建一個宏來檢測它們的IE設置,並在啓用保護模式時通知用戶(如果可能,可能會使用PutProperty方法使用VBA更改此設置)。我目前正在使用Microsoft Internet控件參考。我試過的路線如下(當然是在一個子程序中)。

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("?") 

我不確定什麼數據類型GetProperty實際上返回(因此變體),我不知道在它傳遞的參數。此外,如果這完全是錯誤的做法,我願意採取新的行動。

InternetExplorer對象的GetProperty方法的MSDN article不太有用。

值得一提的是,我對微軟Internet控件和InternetExplorer對象頗爲陌生,這是我第一次使用它。

謝謝你的時間和考慮!

+0

作爲一種變通方法,你可以在網站添加到IE瀏覽器中的受信任站點列表中。我認爲這會禁用該網站的保護模式。 – Sam

+0

我認爲爲了做到這一點,我將不得不修改用戶的註冊表,這不是一個真正可行的選擇。我認爲這是一個不可能完成的任務(考慮到我的限制),只是想獲得專家的建議。 – Soulfire

回答

1

解決方案最終與我的目標大不相同。爲了達到我想要的行爲,我必須與註冊管理機構一起玩,我已經辭職了。雖然這是不受歡迎的,但這是我最終在VBA中做的。

這不是我的最終代碼,因爲我仍在處理該項目,但它已足夠。

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 
0

我不認爲你可以使用GetProperty來讀出瀏覽器的安全設置。從DOC:

您可能想要探索保護模式API描述here或URL安全區域API描述here

相關問題