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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Write REG_MULTI_SZ value in registry

Write REG_MULTI_SZ value in registry

Scheduled Pinned Locked Moved ATL / WTL / STL
windows-adminhelpannouncement
4 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.
  • C Offline
    C Offline
    Cpp_Com
    wrote on last edited by
    #1

    I want to write a REG_MULTI_SZ value (e.g 100-104) in registry. My code is like

    HKEY objHKey;
    CString strReturn;
    CString subkey("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters");

    // Open Registry key for Vlc Path
    if( RegOpenKey( HKEY\_LOCAL\_MACHINE,
    				(LPCTSTR)subkey,	// what to open
    				&objHKey				// on success, handle goes here
    				) == ERROR\_SUCCESS )
    {
    	unsigned char \* format =  new unsigned char \[100\];
    	unsigned char p1\[5\] = "998";
    	unsigned char p2\[5\] = "999";
    	sprintf((char\*)format, "%s\\\\0%s\\\\0\\\\0", p1, p2);
    	int ILenght = 20;//strlen(format);
    
    	unsigned char \*ptr=  (unsigned char \*) strTemp.GetBuffer(0);
    	
    	if(ERROR\_SUCCESS != RegSetValueEx(objHKey,
    					\_T("ReservedPorts"),
    					NULL,
    					REG\_MULTI\_SZ,
    					//(BYTE\*)\_T("1000-1004"),
    					ptr,
    					strTemp.GetLength()))
    					
    	{
    		AfxMessageBox(\_T("Failed to update in registry."));
    	}
    	
    	// Close the registry
    	RegCloseKey( objHKey );
    }
    

    But this is not updating in registry.

    L 1 Reply Last reply
    0
    • C Cpp_Com

      I want to write a REG_MULTI_SZ value (e.g 100-104) in registry. My code is like

      HKEY objHKey;
      CString strReturn;
      CString subkey("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters");

      // Open Registry key for Vlc Path
      if( RegOpenKey( HKEY\_LOCAL\_MACHINE,
      				(LPCTSTR)subkey,	// what to open
      				&objHKey				// on success, handle goes here
      				) == ERROR\_SUCCESS )
      {
      	unsigned char \* format =  new unsigned char \[100\];
      	unsigned char p1\[5\] = "998";
      	unsigned char p2\[5\] = "999";
      	sprintf((char\*)format, "%s\\\\0%s\\\\0\\\\0", p1, p2);
      	int ILenght = 20;//strlen(format);
      
      	unsigned char \*ptr=  (unsigned char \*) strTemp.GetBuffer(0);
      	
      	if(ERROR\_SUCCESS != RegSetValueEx(objHKey,
      					\_T("ReservedPorts"),
      					NULL,
      					REG\_MULTI\_SZ,
      					//(BYTE\*)\_T("1000-1004"),
      					ptr,
      					strTemp.GetLength()))
      					
      	{
      		AfxMessageBox(\_T("Failed to update in registry."));
      	}
      	
      	// Close the registry
      	RegCloseKey( objHKey );
      }
      

      But this is not updating in registry.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2
            sprintf((char\*)format, "%s\\\\0%s\\\\0\\\\0", p1, p2);
      

      The result of the above command will produce the string:

      998\0999\0\0

      which is obviously not what you want; the format string should be "%s\0%s\0\0". You also say that this is not updating in registry; do you get the error message or see some other problem? Are you running this code with administrator privileges and have you opened your registry key with the correct permissions for updating values?

      Unrequited desire is character building. OriginalGriff

      T 1 Reply Last reply
      0
      • L Lost User
              sprintf((char\*)format, "%s\\\\0%s\\\\0\\\\0", p1, p2);
        

        The result of the above command will produce the string:

        998\0999\0\0

        which is obviously not what you want; the format string should be "%s\0%s\0\0". You also say that this is not updating in registry; do you get the error message or see some other problem? Are you running this code with administrator privileges and have you opened your registry key with the correct permissions for updating values?

        Unrequited desire is character building. OriginalGriff

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        great 5p+

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        L 1 Reply Last reply
        0
        • T ThatsAlok

          great 5p+

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
          Never mind - my own stupidity is the source of every "problem" - Mixture

          cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          :thumbsup:

          Unrequited desire is character building. OriginalGriff

          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