Search code examples
windowsprogramming-languageswinrar

WinRar exit code different behavior in SP2/SP3 and 7


I am new to windows programming and have written a small utility with mingw which will unrar a package. The code is as provided below

Descrition:

When the below program is run, the results are as follows

XPSP2 32 bit and Windows 7

  • Untar Operation : Success
  • CreateProcess return code : Non Zero (Success)
  • exit Code : 0 (Success)

XP2SP3 32 bit

  • Untar Operation : Success
  • CreateProcess return code : Non Zero (Success)
  • exit Code : 3221225477

Problem Statement

I am not sure why in XP2SP3 patch only, the winRar operation provides the exit code as Huge positive value. Do you find any problem in the below code? Please help in this regard.


int main()
{
    string ProgramName = "C:\\Program Files\\WinRAR\\WinRAR.exe";   
    STARTUPINFO StartupInfo;
    PROCESS_INFORMATION ProcessInfo;

        memset(&StartupInfo, 0, sizeof(STARTUPINFO));
    memset(&ProcessInfo, 0, sizeof(PROCESS_INFORMATION)

    if (CreateProcess((LPCTSTR)ProgramName.c_str(),(LPCTSTR)"WinRAR.exe x -y -ibck d:\\abc.tar d:\\"),NULL,
    NULL,
    FALSE,
    NORMAL_PRIORITY_CLASS,
    NULL,
    NULL,
    &StartupInfo,
    &ProcessInfo) == 0)
    {
        string tmpStr("Error executing");
        tmpStr += ProgramName;
        cout<<"StmtDesigner"<<tmpStr<<"CreateProcess failed"<<endl;
    }
    else
    {
        string tmpStr("Succes executing");
        tmpStr += ProgramName;
        cout<<"StmtDesigner"<<tmpStr<<"CreateProcess Success"<<endl;



            WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
            DWORD exitCode=0;
            if (GetExitCodeProcess(ProcessInfo.hProcess, &exitCode))
            {
            string tmpStr("GetExitCodeProcess");
            tmpStr += ProgramName;
            cout<<tmpStr<<"WinRAR.exe x -y -ibc<<endl;
            }
    }

    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);

    getch();
    return 0;
}

PS : WinRar 3.8 version trail Mode is used for above testing.


Solution

  • That huge positive number, in hexadecimal, is 0xC0000005. It's a common Windows error, which means "Access Violation". Why exactly are you getting it really depends on what winrar is trying to do, but the problem might be with access rights to files. I suggest you give it a try with ProcMon watching your program's file activity. If accessing one of the files is denied, you'll see it in the log.