how to add Ip address in the registry value
-
hi i need to add Ip Address as the value for the registry. Example,like this Registry Name = public Registry Type = REG_SZ Registry Data = 10.20.40.80 but using below code am able to add only one value as "1" #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { unsigned char szStr[20]="12.45.67.89"; HKEY hKey; // opening a subkey, then creating and setting a value if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT ("SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\s1"), 0, KEY_ALL_ACCESS, &hKey)!=ERROR_SUCCESS) printf("\nError opening the desired subkey (doesn't exist?).\n"); else { if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, szStr, sizeof (szStr)) ==ERROR_SUCCESS) printf("\nThe value of the key was set successfully.\n"); else printf("\nError setting the value of the key.\n"); } RegCloseKey(hKey); return 0; } Output am getting in the registry data field is " 9" could you please help me regarding the above issue.
-
hi i need to add Ip Address as the value for the registry. Example,like this Registry Name = public Registry Type = REG_SZ Registry Data = 10.20.40.80 but using below code am able to add only one value as "1" #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { unsigned char szStr[20]="12.45.67.89"; HKEY hKey; // opening a subkey, then creating and setting a value if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT ("SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\s1"), 0, KEY_ALL_ACCESS, &hKey)!=ERROR_SUCCESS) printf("\nError opening the desired subkey (doesn't exist?).\n"); else { if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, szStr, sizeof (szStr)) ==ERROR_SUCCESS) printf("\nThe value of the key was set successfully.\n"); else printf("\nError setting the value of the key.\n"); } RegCloseKey(hKey); return 0; } Output am getting in the registry data field is " 9" could you please help me regarding the above issue.
You are being very good about using TEXT macros, and TCHAR... while leads me to think you are using UNICODE. In which case, your address needs to be stored as a TCHAR array also. Ie:
TCHAR szStr [] = _T("12.45.67.89");
...
if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, (BYTE *)szStr, sizof (TCHAR) * lstrlen (szStr)) ==ERROR_SUCCESS)
...I'm assuming your access of hKey is succeeding? Can you delete the "public" value using regedit, and see it getting re-created? Iain.
-
hi i need to add Ip Address as the value for the registry. Example,like this Registry Name = public Registry Type = REG_SZ Registry Data = 10.20.40.80 but using below code am able to add only one value as "1" #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { unsigned char szStr[20]="12.45.67.89"; HKEY hKey; // opening a subkey, then creating and setting a value if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT ("SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\s1"), 0, KEY_ALL_ACCESS, &hKey)!=ERROR_SUCCESS) printf("\nError opening the desired subkey (doesn't exist?).\n"); else { if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, szStr, sizeof (szStr)) ==ERROR_SUCCESS) printf("\nThe value of the key was set successfully.\n"); else printf("\nError setting the value of the key.\n"); } RegCloseKey(hKey); return 0; } Output am getting in the registry data field is " 9" could you please help me regarding the above issue.
TCHAR
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
TCHAR
Mark Salsbery Microsoft MVP - Visual C++ :java:
thanks Mark Salsbery the above sample program is working fine, am able to enter the Ip Address properly. thanks a lot :)
-
You are being very good about using TEXT macros, and TCHAR... while leads me to think you are using UNICODE. In which case, your address needs to be stored as a TCHAR array also. Ie:
TCHAR szStr [] = _T("12.45.67.89");
...
if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, (BYTE *)szStr, sizof (TCHAR) * lstrlen (szStr)) ==ERROR_SUCCESS)
...I'm assuming your access of hKey is succeeding? Can you delete the "public" value using regedit, and see it getting re-created? Iain.
thanks Iain Clarke it's working fine......... :)