Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to add Ip address in the registry value

how to add Ip address in the registry value

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialwindows-adminquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adhilingam
    wrote on last edited by
    #1

    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.

    I M 2 Replies Last reply
    0
    • A adhilingam

      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.

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • A adhilingam

        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.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3
        TCHAR
        

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A 1 Reply Last reply
        0
        • M Mark Salsbery
          TCHAR
          

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          A Offline
          A Offline
          adhilingam
          wrote on last edited by
          #4

          thanks Mark Salsbery the above sample program is working fine, am able to enter the Ip Address properly. thanks a lot :)

          1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            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.

            A Offline
            A Offline
            adhilingam
            wrote on last edited by
            #5

            thanks Iain Clarke it's working fine......... :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups