?
Solved

problem withCreateProcess

Posted on 2006-07-03
5
Medium Priority
?
228 Views
Last Modified: 2013-11-20
Hi All
I am having a problem in my application, what I am doing is:
Calling a function SaveKeys(TCHAR *) within a loop and this function save the specified registry key to a .reg file,
for this using CreateProcess( ) for calling regedit.exe from command line and WaitForSingleObject( ) function.
code looks like this

for (int i = 0; i < 10; i++)
{
// some code here
SaveKeys(cRegistryKey ); // for specified Registry Key
}

void MyClass::SaveKeys(TCHAR *cRegistryKey)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInformation;

CreateProcess(NULL, cCommand,NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|CREATE_SUSPENDED,NULL, NULL, &StartupInfo, &ProcessInformation);
WaitForSingleObject( ProcessInformation.hProcess, INFINITE );

}
//e.g. Here cCommand = regedit /e C:\File.reg HKEY_CURRENT_USER\MyKey

Now what is my problem is that here WaitForSingleObject( ) function is not working. and only a single reg file is created.
and when use Sleep(1000) then all the 10 reg file are created.

So please tell me that how should I overcome this problem.

Please reply
Thanks
 
0
Comment
Question by:davinder101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 17030860
Initialize the STARTUPINFO struct:

   ZeroMemory  (   &StartupInfo,    sizeof  (   STARTUPINFO));

   StartupInfo.cb           =   sizeof  (   STARTUPINFO);
   StartupInfo.dwFlags      =   STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow  =   SW_SHOWNORMAL;
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 200 total points
ID: 17031001
I'd write it directly into the registry rather than creating a file on disc then 'running' the file.  (Look at CRegKey in help)
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question