Can WinHttpGetIEProxyConfigForCurrentUser obtain proxy from WPAD - c++

I was able to obtain proxy data that was manually entered into proxy settings on my Windows machine (Use a proxy server for your LAN option was checked) but I'm wondering if WinHttpGetIEProxyConfigForCurrentUser will also set field LPWSTR lpszProxy in case when Use automatic configuration script or Automatically detect settings checkboxes are checked in this dialog:
If not, how to obtain address of the currently used proxy?

You will get that in lpszAutoConfigUrl.
lpszAutoConfigUrl is variable of the structure WINHTTP_CURRENT_USER_IE_PROXY_CONFIG that is parameter of WinHttpGetIEProxyConfigForCurrentUser
Documentation link.
https://learn.microsoft.com/en-us/windows/desktop/api/winhttp/ns-winhttp-winhttp_current_user_ie_proxy_config
Code used for a quick test:
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG pProxyConfig;
pProxyConfig.fAutoDetect = TRUE;
WinHttpGetIEProxyConfigForCurrentUser(&pProxyConfig);

WinHttpGetIEProxyConfigForCurrentUser() can be used to determine if both:
"Automatically detect settings" is enabled (member 'fAutoDetect' of WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure) and
"Automatic configuration script" is set (member 'lpszAutoConfigUrl' of WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure)
However, to obtain the proxy address itself for particular endpoint, WinHttpGetProxyForUrl() should be used.
If you already have 'Automatic configuration script' read from IE Internet options, you may use it like this:
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions= {0};
WINHTTP_PROXY_INFO proxyInfo= {0};
PCWSTR endpointUrl = <URL, that you need proxy for>;
autoProxyOptions.lpszAutoConfigUrl = <auto config address obtain from WINHTTP_CURRENT_USER_IE_PROXY_CONFIG>;
.
. //set suitable autoProxyOptions flags
.
if (!WinHttpGetProxyForUrl(hSession, endpointUrl, &autoProxyOptions, &proxyInfo))
{
GetLastError();
}

Related

WebView2 proxy C++

I found this thread on GitHub, but seems that the code is not C++:
WebView2 _webView2 = new WebView2();
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions();
// Set a proxy pac for the browser
// options.AdditionalBrowserArguments = "--proxy-pac-url=http://myproxy.com/my.pac";
// Set the proxy for the browser
options.AdditionalBrowserArguments = "--proxy-server=\"foopy:99\"";
// Create the environment manually
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, null, options);
await _webView2 .EnsureCoreWebView2Async(env);
So the only what am I asking for is to provide the solution for setting up a proxy for WebView2 via C++.
I have ICoreWebView2 interface, but it doesn’t have EnsureCoreWebView2Async method. In another hand, I have CoreWebView2EnvironmentOptions class.
auto opt = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
opt->put_AdditionalBrowserArguments(L"--proxy-server=\"SERVER\"");
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, opt.Get(), Microsoft::WRL::Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[hwnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
...
}).Get());
Instead of SERVER put ip address or something else.
I tested, it works, but seems there is a bug (or feature): you can’t create two or more webviews with different run-arguments.
To those looking to specify webview environment options and cannot find CoreWebView2EnvironmentOptions in C++ similar to what is available in .Net. Visit documentation page for ICoreWebView2EnvironmentOptions and you should find this line:
A default implementation is provided in WebView2EnvironmentOptions.h
Include WebView2EnvironmentOptions.h and create CoreWebView2EnvironmentOptions as below
#include <WebView2EnvironmentOptions.h>
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
// Use options however you want. I simply added an argument to autoplay videos.
options->put_AdditionalBrowserArguments(L"--autoplay-policy=no-user-gesture-required");
HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
subFolder, m_userDataFolder.c_str(), options.Get(),
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
this, &AppWindow::OnCreateEnvironmentCompleted)
.Get());

Peoplecode - how to create cookies?

We are trying to create a cookie in the PeopleSoft Peoplecode by using the %Response object.
However, the code we tried is failing.
&YourCookie = %Response.AddCookie("YourCookieName", "LR");
Another snippet we tried to create the cookie
Local object &Response = %Response;
Local object &YourCookie;
&YourCookie = &Response.CreateCookie("YourCookieName");
&YourCookie.Domain = %Request.AuthTokenDomain;
&YourCookie.MaxAge = -1; /* Makes this a session cookie (default) */
&YourCookie.Path = "/";
&YourCookie.Secure = True; /* Set to true if using https (will still work with http) */
&YourCookie.Value = "Set the cookie value here. Encrypt sensitive information.";
The document reference points to IScript functions called CreateCookie methods etc.
http://docs.oracle.com/cd/E15645_01/pt850pbr0/eng/psbooks/tpcr/chapter.htm?File=tpcr/htm/tpcr21.htm
However, these don't work in Peoplecode. We don't have the knowledge to create IScript or use it. Any insight with the People code API for cookies or IScript is much appreciated.
I just tested on PeopleTools 8.54.11 and was able to create a cookie using the snippet you provided above.
I did find I had an issue if I set
&YourCookie.Secure = True;
in an environment where I was using HTTP.
If you set Secure to False the cookie will be available in both HTTP and HTTPS
if you set Secure to True the cookie is only available in HTTPS
PeopleTools 8.54 Documentation showing the CreateCookie method
I have been trying to do this (same code snippet) from within signon peoplecode, tools release is 8.54.09. I can execute the first two lines of code, but as soon as the line of code executing the CreateCookie() method executes, I get tossed out / end up on the signon error page.
This seems to support the previous answer saying that the API has removed the method, but the answer before that says it has been successful on tools 8.54.11 -- does that mean they removed it, then put it back, and I happen to be stuck with a release where it was removed? :-/

Qt/C++ getting OS proxy settings

I need to retrieve the proxy settings on Windows. They have been set by an admin, so they reside in the registry at locations:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
ProxySettingsPerUser = 0x00000000 (0)
This entry is giving the information whether the proxy settings need to be read from HKCU(ProxySettingsPerUser=1) or HKLM(ProxySettingsPerUser=0).
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings
ProxyEnable = 0x00000001 (1)
ProxyServer = Host:Port
When I try to read them directly, the default value/string is returned (i.e. not the actual contents of the variable):
Code:
#define HKLM_INTERNET_SETTINGS_KEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
//[...]
QSettings regHKLM( HKLM_INTERNET_SETTINGS_KEY, QSettings::NativeFormat );
QString read = regHKLM.value( "ProxyServer", "default" ).toString();
logDebug(QString("ProxyServer %1").arg(read));
Other entries in the same location, such as CodeBaseSearchPath = "CODEBASE" or WarnOnIntranet = 0x00000001 (1), can be read without a problem.
THe second approach tried was to read the proxy settings by using the MSDN functions ::WinHttpGetIEProxyConfigForCurrentUser and ::WinHttpGetProxyForUrl. The code is working fine when trying to read HKCU settings (given both manually host-port or as pac file). But when the settings need to be retrieved from HKLM, the following error is returned:
ERROR_WINHTTP_AUTODETECTION_FAILED
12180
Returned by WinHttpDetectAutoProxyConfigUrl if WinHTTP was unable to discover the URL of the Proxy Auto-Configuration (PAC) file.
Is there another approach to retrieving the HKLM proxy settings?
If the approaches described above should have worked, is there a special condition/privilage that needs to be fulfilled before the settings can be read? (in the first approached, the application already has elevated the privilage level to maximum possible, and the manifest file is set to level "asInvoker")
Best regards,
Kornrade

wbemtest doesn't show certain data after executing a query

I have BitLocker enabled on my machine and I want to use the wbemtest.exe utility to view properties about the Bitlocker data.
According to the properties section at MSDN, some of the data that I want to retrieve are DeviceID, DriveLetter, PersistentVolumeID, and ProtectionStatus.
However, when I execute the query
SELECT * from Win32_EncryptableVolume
using wbemtest.exe, only one object gets returned, and that is BitLocker DeviceID. I also want this query to return the DriveLetter and the other properties. What do I do to retrieve these? The data should be there, because my C# app using System.Management is able to get data on the other properties without any trouble (by assigning the return value of a ManagementClass GetInstances() method to a a ManagementObjectCollection.)
It turns out that I am able to view the data I need quite simply by using the WMI Code Creator utility.
I found this information on windows-noob

How to Change Default search provider of IE 9 by registry Editing through C++ program?

I want to change the default search provider of IE (9) by editing the registry file. I have followed the steps given in the link: http://www.online-tech-tips.com/internet-explorer-tips/change-default-search-engine-ie/.
But when I change DefaultScope value to a scope in SearchScopes, then restart the computer, or open IE, make a search in address bar, or close IE. The value of DefaultScope is restore to previous value.
Why? Or what is my mistake?
How to change the search provider engine of IE programatically (not in IE, may be through registry, or in my C++ code)? (I write a C++ program that need to change IE's search provider engine)
I have written this function for Firefox or Chrome. It works well.
With Firefox, those information is stored in the prefs.js file. I can
read or write information requisite to this file easily. With Chrome,
those information is stored in two files in user profile folder:
Preferences and Web Data files. The Preferences file is a JSON file. I
get those information easily by parsing this JSON file. But to set
search engine provider information for Chrome. We need to change those
information in Web Data file. Web Data file is a SQLite file. I use
SQLite library to access this.
With Internet Explorer, I can get those information in that registry
path. But I can't set those information with that registry path. So, I
think, like Chrome, IE (or registry) needs to change those information
somewhere. But I don't know where.
Here is a detailed answer to your question.
There are two options you may choose from use IOpenServiceManager:
CComQIPtr<IOpenServiceManager> spManager;
check(spManager.CoCreateInstance(__uuidof(OpenServiceManager), CLSCTX_ALL));
CComQIPtr<IOpenService> spService;
check(spManager->InstallService(PU_POSTINSTALL_ANT_SEARCH_PROVIDER_XML, &spService));
if(makeItDefault)
{
// Request that the user change their search default
check(spService->SetDefault( TRUE, hPromptParent ));
}
or modify the registry:
LPCWSTR searchScopesKeyName = L"Software\\Microsoft\\Internet Explorer\\SearchScopes";
createKey(rootKey, HKEY_CURRENT_USER, searchScopesKeyName);
std::wstring clsidString = findProviderClsid(false);
if( clsidString.empty() )
clsidString = mc_providerClsidString;
if( makeItDefault )
setStringValue( rootKey, mc_defaultScopeValueName, clsidString.c_str() );
ATL::CRegKey subKey;
createKey(subKey, rootKey.m_hKey, clsidString.c_str() );
setStringValue( subKey, mc_displayNameValueName, mc_providerName );
setStringValue( subKey, mc_faviconUrlValueName, mc_providerFaviconURL );
setStringValue( subKey, mc_urlValueName, mc_providerURL );
Just giving a side note that SetDefault function was deprecated on Microsoft Edge browser. Also, after KB3148198 update, it's blocked. Function will return
OS_E_CANCELLED instead.