Solved

problem withCreateProcess

Posted on 2006-07-03
5
219 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
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 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 50 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now