Executing .reg file

Hi Experts,

I am wanting to execute a .reg file w/o the message "Information in '.reg file' has been successfully entered into the registry".  How would I do this programatically?  Also, I understand that the WinExec function returns automatically w/o completion of the running program to execute the next line of code.  How do you use the ShellExecuteExe function to wait until the running program finishes to execute the next line of code?  I will need a detailed explanation of the ShellExecuteExe function because I have never used it before.  I appreciate your help in advance.

-Thanks :0)

Anthem
LVL 2
AnthemAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You can do this by using the following code (a little bit more straightfoward than using 'ShellExecuteEx()', which will call 'CreateProcess()' internally):

LONG    APIENTRY    LoadRegFile (   LPSTR pszRegFile)
{
    BOOL                bRes;
    STARTUPINFO         si;
    PROCESS_INFORMATION pi;

    char                acCmd       [   MAX_PATH];

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb           =   sizeof  (   STARTUPINFO);
    si.dwFlags      =   STARTF_USESHOWWINDOW;
    si.wShowWindow  =   SW_HIDE;

    wsprintf    (   acCmd,      "regedit.exe /s %s",    pszRegFile);

    bRes    =   CreateProcess   (   NULL,
                                    acCmd,
                                    NULL,
                                    NULL,
                                    FALSE,
                                    NORMAL_PRIORITY_CLASS ,
                                    GetEnvironmentStrings   (),
                                    NULL,
                                    &si,
                                    &pi
                                );

    if  (   bRes)
        {
            WaitForSingleObject (   pi.hProcess,    INFINITE);

            CloseHandle (   pi.hProcess);
            CloseHandle (   pi.hThread);

            return  (   0);
        }
     else   return  (   GetLastError());


    return  (   0);
}


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
However, if you 'insist' in using 'ShellExecuteEx()', use

LONG    APIENTRY    LoadRegFile (   LPSTR pszRegFile)
{
    SHELLEXECUTEINFO sei;
   
    ZeroMemory  (   &sei,   sizeof  (   sei));

    sei.cbSize          =   sizeof  (   sei);  
    sei.fMask           =   SEE_MASK_NOCLOSEPROCESS ;
    sei.lpVerb          =   "open";
    sei.lpFile          =   pszRegFile;
    sei.lpParameters    =   "/s";
    sei.nShow           =   SW_HIDE;

    bRes    =   ShellExecuteEx  (   &sei);

    if  (   bRes)
        {
            WaitForSingleObject (   sei.hProcess,    INFINITE);

            CloseHandle (   sei.hProcess);

            return  (   0);
        }
     else   return  (   GetLastError());


    return  (   0);
}
0
AnthemAuthor Commented:
jkr,

Worked perfectly.  I did use the CreateProcess() function.  Truly appreciate all of your help on this! :0)

Thank you so much,

Anthem :0)

-Have a great rest of the day
0
jkrCommented:
Rest of the day? 11:35pm here, so I really hope that the last (next) 25 minutes will be great ;-)
0
AnthemAuthor Commented:
Hehehehe, you are too cute.  Have a lot more of the day to go here.  Hope the rest of your 25 minutes goes wonderfully, and hope you have a great rest of the week, lol :0)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.