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. C / C++ / MFC
  4. Problem with CreateProcess

Problem with CreateProcess

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelpquestion
5 Posts 4 Posters 1 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.
  • R Offline
    R Offline
    rajeevktripathi
    wrote on last edited by
    #1

    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

    G V V 4 Replies Last reply
    0
    • R rajeevktripathi

      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

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      why bother shelling an external process when you can use something like http://www.codeproject.com/system/NtRegistry.asp[^] to do it directly from your program - if you look under http://www.codeproject.com/system[^] you'll find lots more goodies to help you 'g'

      1 Reply Last reply
      0
      • R rajeevktripathi

        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

        V Offline
        V Offline
        Viorel
        wrote on last edited by
        #3

        Uninitialized STARTUPINFO structure is one of the problems of your code. It can be fixed like this:

        STARTUPINFO StartupInfo = { sizeof(STARTUPINFO) };
        
        1 Reply Last reply
        0
        • R rajeevktripathi

          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

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          In addition, it seems that the invoked regedit tools cannot work in multi-instance mode. For example, I cannot start more then one regedit application from Windows menu or command line. That's why only some of your calls work. This probably means that you cannot do multi-threaded export using regedit tool.

          1 Reply Last reply
          0
          • R rajeevktripathi

            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

            V Offline
            V Offline
            valikac
            wrote on last edited by
            #5

            CREATE_SUSPENDED ResumeThread() Kuphryn

            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