loading registry file programatically
-
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 !
-
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 !
Try specifying some value other than
0
forsi.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
-
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 !
This looks strange:
ZeroMemory( p, sizeof(pi) );
-
Try specifying some value other than
0
forsi.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
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 !
-
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 !