徵狀
如果您的電腦從未執行 Microsoft Internet Explorer,您可以使用WinHttpGetIEProxyConfigForCurrentUser函式在任何程式中,您會收到下列錯誤訊息:
ERROR_FILE_NOT_FOUND
原因
WinHttpGetIEProxyConfigForCurrentUser函式會使用下列登錄子機碼:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet 設定Internet Explorer 會執行第一次時,都會建立這個登錄子機碼。如果您的電腦未執行 Internet Explorer,此登錄子機碼不存在。當您呼叫WinHttpGetIEProxyConfigForCurrentUser函式在程式中,函式會搜尋此登錄項目,而且找不到它,並收到錯誤訊息。
解決方案
若要解決這個問題,請啟動 Internet Explorer,然後使用WinHttpGetIEProxyConfigForCurrentUser函式在任何程式中。
其他相關資訊
重現問題的步驟
-
登入的電腦,在 Internet Explorer 從未使用。
-
啟動 Microsoft Visual Studio .NET。
-
在 [檔案] 功能表上指向 [新增],然後按一下專案。
-
按一下 [專案類型] 下的 [ Visual C++ 的專案]。
-
按一下 [範本] 下的 [ Win32 專案]。
-
在 [名稱] 方塊中,輸入測試,然後按一下[確定]。
-
在 [歡迎使用 Win32 應用程式精靈] 頁面上,按一下 [應用程式設定]。
-
在應用程式類型] 之下按一下 [主控台應用程式,,,然後按一下 [完成]。會建立 Test.cpp 檔案。
-
Test.cpp 檔案中現有的程式碼取代下列程式碼中:
#include "stdafx.h"#include <Windows.h>#include <Winhttp.h>using namespace std;void main(){WINHTTP_CURRENT_USER_IE_PROXY_CONFIG MyProxyConfig;if(!WinHttpGetIEProxyConfigForCurrentUser(&MyProxyConfig)){//check the errorDWORD Err = GetLastError();cout << "WinHttpGetIEProxyConfigForCurrentUser failed with the following error number: " << Err << endl;switch (Err){case ERROR_FILE_NOT_FOUND:cout << "The error is ERROR_FILE_NOT_FOUND" << endl;break;case ERROR_WINHTTP_INTERNAL_ERROR:cout << "ERROR_WINHTTP_INTERNAL_ERROR" << endl;break;case ERROR_NOT_ENOUGH_MEMORY:cout << "ERROR_NOT_ENOUGH_MEMORY" << endl;break;default:cout << "Look up error in header file." << endl; }//end switch}//end ifelse{//no error so check the proxy settings and free any stringscout << "Auto Detect is: " << MyProxyConfig.fAutoDetect << endl;if(NULL != MyProxyConfig.lpszAutoConfigUrl){wcout << "AutoConfigURL is: " << MyProxyConfig.lpszAutoConfigUrl << endl;GlobalFree(MyProxyConfig.lpszAutoConfigUrl);}if(NULL != MyProxyConfig.lpszProxy){wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxy << endl;GlobalFree(MyProxyConfig.lpszProxy);}if(NULL != MyProxyConfig.lpszProxyBypass){wcout << "AutoConfigURL is: " << MyProxyConfig.lpszProxyBypass << endl;GlobalFree(MyProxyConfig.lpszProxyBypass);}}//end elsecout << "finished!";}//end main
注意Winhttp.h 和 Winhttp.lib 檔案會包含於 Microsoft 平台軟體開發套件 (SDK)。若要下載 Platform sdk 》,請造訪下列 Microsoft 網站:
-
在 [專案] 功能表上按一下 [測試內容]。
-
在左窗格中,按兩下 [連結器]。
-
在連結器,請按一下 [輸入]。
-
在右窗格中,在 [其他相依性] 欄位中,輸入winhttp.lib ,然後按一下[確定]。
-
按一下 [建置] 功能表的 [建置方案]。
-
請按 CTRL + F5 執行程式,但不偵錯工具。您會收到 < 徵狀=""> 一節所述的錯誤訊息。
參考
如需詳細資訊,請造訪下列 Microsoft 開發人員網路 (MSDN) 網站: