Hi, guys i am trying to create a String in the Windows Registry to imput some nice Proxy Adress. But i failed to input the correct datatype. I do not have any problems with Type (DWORD)... But (REG_SZ) has not work. Can someone tell me how can i input in the Registry a HTTPs Adress like "HTTPS://www.google.com" as a test. :)

Thank you

Below my code the secound part works fine :) I am struggling with REG_SZ :(

include
include

void add_proxy()

long pro;
HKEY hKeyp;
// under this field should be the Type REG_SZ to input a Proxy Adress
REG_SZ "proxy";
pro = RegCreateKeyEx(
    HKEY_CURRENT_USER,
    L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\test",
    0,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS | KEY_WOW64_32KEY,
    NULL,
    &hKeyp,
    NULL);

// Status of work
if (pro != ERROR_SUCCESS)
{
    std::cout << "Registry creation failed & Error No - " << GetLastError() << std::
        endl;
}
std::cout << "Registry creation success" << std::endl;

lReg = RegSetValueEx(
    hKeyp,
    L"ProxyEnable",
    NULL,
    REG_SZ,
    (LPBYTE)&value,
    sizeof(value)
);
//Status of work
if (pro != ERROR_SUCCESS)
{
    std::cout << "Registry creation failed & Error No - " << GetLastError() << std::
        endl;
}
std::cout << "Registry creation success" << std::endl;

RegCloseKey(pro);

//Part 2

LONG lReg;
HKEY hKey;
DWORD dwData =00000001;
lReg = RegCreateKeyEx(
    HKEY_CURRENT_USER,
    L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
    0,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS | KEY_WOW64_32KEY,
    NULL,
    &hKey,
    NULL);
    // Status of work
if (lReg != ERROR_SUCCESS)
{
    std::cout << "Registry creation failed & Error No - " << GetLastError() << std::
        endl;
}
std::cout << "Registry creation success" << std::endl;

lReg = RegSetValueEx(
    hKey,
    L"ProxyEnable",
    NULL,
    REG_DWORD,
    (LPBYTE)&dwData,
    sizeof(dwData)
);
    //Status of work
if (lReg != ERROR_SUCCESS)
{
    std::cout << "Registry creation failed & Error No - " << GetLastError() << std::
        endl;
}
std::cout << "Registry creation success" << std::endl;

RegCloseKey(hKey);
system("PAUSE");

I'll comment the code, I gather that the RegCreateKeyEx call succeeds.

lReg = RegSetValueEx(
    hKeyp,
    L"ProxyEnable",
    NULL,
    REG_SZ,
    (LPBYTE)&value,  // where is the value?
    sizeof(value)    // for a REG_SZ this should be the string length in bytes including the terminating null
);
commented: the Value should be initialzied earlier like in the second part of my code.. but i do not know which datatype i exactly need and in which syntax :( +0

the Value should be initialzied earlier like in the second part of my code.. but i do not know which datatype i exactly need and in which syntax :(

Try something like this:

WCHAR value[] = L"Some Proxy";
DWORD len = (lstrlenW(value) + 1)*sizeof(WCHAR);

lReg = RegSetValueExW(
    hKeyp,
    L"ProxyEnable",
    NULL,
    REG_SZ,
    (LPBYTE)value,  
    len    
);

Thank you it Works <3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.