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. loading registry file programatically

loading registry file programatically

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomwindows-adminoopworkspace
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
    act_x
    wrote on last edited by
    #1

    I attempted to do this in a DLL and it worked just fine . However moving the code inside COM exe does not report any error but does not load the information in the registry .

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    	ZeroMemory( &si, sizeof(si) );
    	si.cb = sizeof(si);
    	ZeroMemory( &pi, sizeof(pi) );		
    	//strLocalFileName = "/a " + strLocalFileName;
    	CString strLocalFileName = CString(\_T("regedit.exe /s ")) + strRegFileName;
    
    		// Start the child process. 
    	if( !CreateProcess(  NULL,   // No module name (use command line)
    		strLocalFileName.GetBuffer(0),      // Command line
    		NULL,           // Process handle not inheritable
    		NULL,           // Thread handle not inheritable
    		TRUE,          // Set handle inheritance to FALSE
    		NORMAL\_PRIORITY\_CLASS,              // No creation flags
    		NULL,           // Use parent's environment block
    		NULL,           // Use parent's starting directory 
    		&si,            // Pointer to STARTUPINFO structure
    		&pi )           // Pointer to PROCESS\_INFORMATION structure
    	) 
    	{
    		//AfxMessageBox("Error Creating Process");
    		int error = GetLastError() ;
    		CloseHandle(pi.hProcess) ; 
    		return false ; 
    	}
    	else
    	{
    		ATLTRACE("GetLastError = %d\\n",GetLastError()); 
    		WaitForSingleObject( pi.hProcess, INFINITE );
    		DWORD dwCode = 0; 
    		GetExitCodeProcess  (   pi.hProcess,    &dwCode);
    		CloseHandle(pi.hProcess); 					
    
    	}
    

    Any help is appreciated !

    Engineering is the effort !

    D M 2 Replies Last reply
    0
    • A act_x

      I attempted to do this in a DLL and it worked just fine . However moving the code inside COM exe does not report any error but does not load the information in the registry .

      STARTUPINFO si;
      PROCESS_INFORMATION pi;

      	ZeroMemory( &si, sizeof(si) );
      	si.cb = sizeof(si);
      	ZeroMemory( &pi, sizeof(pi) );		
      	//strLocalFileName = "/a " + strLocalFileName;
      	CString strLocalFileName = CString(\_T("regedit.exe /s ")) + strRegFileName;
      
      		// Start the child process. 
      	if( !CreateProcess(  NULL,   // No module name (use command line)
      		strLocalFileName.GetBuffer(0),      // Command line
      		NULL,           // Process handle not inheritable
      		NULL,           // Thread handle not inheritable
      		TRUE,          // Set handle inheritance to FALSE
      		NORMAL\_PRIORITY\_CLASS,              // No creation flags
      		NULL,           // Use parent's environment block
      		NULL,           // Use parent's starting directory 
      		&si,            // Pointer to STARTUPINFO structure
      		&pi )           // Pointer to PROCESS\_INFORMATION structure
      	) 
      	{
      		//AfxMessageBox("Error Creating Process");
      		int error = GetLastError() ;
      		CloseHandle(pi.hProcess) ; 
      		return false ; 
      	}
      	else
      	{
      		ATLTRACE("GetLastError = %d\\n",GetLastError()); 
      		WaitForSingleObject( pi.hProcess, INFINITE );
      		DWORD dwCode = 0; 
      		GetExitCodeProcess  (   pi.hProcess,    &dwCode);
      		CloseHandle(pi.hProcess); 					
      
      	}
      

      Any help is appreciated !

      Engineering is the effort !

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Try specifying some value other than 0 for si.wShowWindow. That way you can see if an error is popping up (and quickly disappearing).

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      A 1 Reply Last reply
      0
      • A act_x

        I attempted to do this in a DLL and it worked just fine . However moving the code inside COM exe does not report any error but does not load the information in the registry .

        STARTUPINFO si;
        PROCESS_INFORMATION pi;

        	ZeroMemory( &si, sizeof(si) );
        	si.cb = sizeof(si);
        	ZeroMemory( &pi, sizeof(pi) );		
        	//strLocalFileName = "/a " + strLocalFileName;
        	CString strLocalFileName = CString(\_T("regedit.exe /s ")) + strRegFileName;
        
        		// Start the child process. 
        	if( !CreateProcess(  NULL,   // No module name (use command line)
        		strLocalFileName.GetBuffer(0),      // Command line
        		NULL,           // Process handle not inheritable
        		NULL,           // Thread handle not inheritable
        		TRUE,          // Set handle inheritance to FALSE
        		NORMAL\_PRIORITY\_CLASS,              // No creation flags
        		NULL,           // Use parent's environment block
        		NULL,           // Use parent's starting directory 
        		&si,            // Pointer to STARTUPINFO structure
        		&pi )           // Pointer to PROCESS\_INFORMATION structure
        	) 
        	{
        		//AfxMessageBox("Error Creating Process");
        		int error = GetLastError() ;
        		CloseHandle(pi.hProcess) ; 
        		return false ; 
        	}
        	else
        	{
        		ATLTRACE("GetLastError = %d\\n",GetLastError()); 
        		WaitForSingleObject( pi.hProcess, INFINITE );
        		DWORD dwCode = 0; 
        		GetExitCodeProcess  (   pi.hProcess,    &dwCode);
        		CloseHandle(pi.hProcess); 					
        
        	}
        

        Any help is appreciated !

        Engineering is the effort !

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #3

        This looks strange:

        ZeroMemory( p, sizeof(pi) );

        1 Reply Last reply
        0
        • D David Crow

          Try specifying some value other than 0 for si.wShowWindow. That way you can see if an error is popping up (and quickly disappearing).

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

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

          so basically I am trying to create a process to run

          regedit /s C:\Program Files\Common Files\MyApp\1.reg

          For debugging purposes I removed the /s for regedit and I see that it chops the path by space So it keeps asking if I want to enter the entry C:\Program Files Common Files\MyApp\1.reg Is there a way this can be prevented ? These files are present in the current working directory of the exe and pro grammatically obtained via GetModuleFileName

          Engineering is the effort !

          A 1 Reply Last reply
          0
          • A act_x

            so basically I am trying to create a process to run

            regedit /s C:\Program Files\Common Files\MyApp\1.reg

            For debugging purposes I removed the /s for regedit and I see that it chops the path by space So it keeps asking if I want to enter the entry C:\Program Files Common Files\MyApp\1.reg Is there a way this can be prevented ? These files are present in the current working directory of the exe and pro grammatically obtained via GetModuleFileName

            Engineering is the effort !

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

            thanks for steering me into resolving this . The key was to enclose the file path in quotes before supplying it to regedit. But I wonder why and how this would be different in a DLL that I developed .

            Engineering is the effort !

            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