{"record":{"id":"072196b33895a9b6","repo":"java-native-access/jna","slug":"could-not-set-proxy-blanket","errorCode":null,"errorMessage":"Could not set proxy blanket.","messagePattern":"Could not set proxy blanket\\.","errorType":"exception","errorClass":"com.sun.jna.platform.win32.COM.COMException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java","lineNumber":543,"sourceCode":"            throw new COMException(\"Failed to create WbemLocator object.\");\n        }\n\n        // Step 4: -----------------------------------------------------\n        // Connect to WMI through the IWbemLocator::ConnectServer method\n        // Connect to the namespace with the current user and obtain pointer\n        // pSvc to make IWbemServices calls.\n        IWbemServices services = loc.ConnectServer(namespace, null, null, null, 0, null, null);\n        // Release the locator. If successful, pSvc contains connection\n        // information\n        loc.Release();\n\n        // Step 5: --------------------------------------------------\n        // Set security levels on the proxy -------------------------\n        HRESULT hres = Ole32.INSTANCE.CoSetProxyBlanket(services, Ole32.RPC_C_AUTHN_WINNT, Ole32.RPC_C_AUTHZ_NONE, null,\n                Ole32.RPC_C_AUTHN_LEVEL_CALL, Ole32.RPC_C_IMP_LEVEL_IMPERSONATE, null, Ole32.EOAC_NONE);\n        if (COMUtils.FAILED(hres)) {\n            services.Release();\n            throw new COMException(\"Could not set proxy blanket.\", hres);\n        }\n        return services;\n    }\n\n}\n","sourceCodeStart":525,"sourceCodeEnd":549,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java#L525-L549","documentation":"After IWbemLocator::ConnectServer succeeds, connectServer calls CoSetProxyBlanket to set authentication (WINNT) and impersonation (IMPERSONATE) levels on the IWbemServices proxy. A failing HRESULT here releases the services and throws COMException \"Could not set proxy blanket.\", typically meaning the COM security settings are incompatible.","triggerScenarios":"CoSetProxyBlanket returns a failure HRESULT — commonly because CoInitializeSecurity was already called with incompatible settings (e.g. impersonation level below RPC_C_IMP_LEVEL_IMPERSONATE or authentication level too low) for this process, or a previous connection changed proxy security.","commonSituations":"Application called CoInitializeSecurity earlier with different authn/imp levels; mixing libraries that each set process-wide COM security; remote WMI where the server rejects the requested authentication; running in restricted service accounts or containers.","solutions":["Call CoInitializeSecurity once per process with RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, RPC_C_AUTHN_LEVEL_CALL (or DEFAULT), RPC_C_IMP_LEVEL_IMPERSONATE before creating WMI connections — or don't call it at all so JNA's defaults apply.","Ensure no other library in the process sets conflicting COM security; align all consumers on one setting.","Check the wrapped HRESULT in the COMException for the exact reason (e.g. E_ACCESSDENIED).","For remote WMI, verify credentials/domain and DCOM permissions (dcomcnfg)."],"exampleFix":"// before\n// some framework already called:\nOle32.INSTANCE.CoInitializeSecurity(null, -1, null, null, Ole32.RPC_C_AUTHN_LEVEL_NONE, Ole32.RPC_C_IMP_LEVEL_IDENTIFY, null, Ole32.EOAC_NONE, null);\n// after\nOle32.INSTANCE.CoInitializeSecurity(null, -1, null, null, Ole32.RPC_C_AUTHN_LEVEL_CALL, Ole32.RPC_C_IMP_LEVEL_IMPERSONATE, null, Ole32.EOAC_NONE, null);","handlingStrategy":"try-catch","validationCode":"// ensure process-wide COM security is compatible before WMI use:\nOle32.INSTANCE.CoInitializeSecurity(null, -1, null, null,\n    Ole32.RPC_C_AUTHN_LEVEL_CALL, Ole32.RPC_C_IMP_LEVEL_IMPERSONATE, null, Ole32.EOAC_NONE, null);","typeGuard":null,"tryCatchPattern":"try {\n    IWbemServices svc = WbemcliUtil.connectServer(ns);\n} catch (COMException e) {\n    if (e.getMessage().contains(\"proxy blanket\")) { /* align CoInitializeSecurity settings or check credentials */ }\n}","preventionTips":["Call CoInitializeSecurity exactly once with impersonate-level settings","Avoid mixing libraries that set conflicting COM security","For remote WMI, verify account, domain, and DCOM permissions"],"tags":["windows","wmi","com","jna","security"],"backgroundTag":"api-error-response","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}