Solved

CreateProcess( not inhiert handle not working

Posted on 2004-10-26
473 Views
Last Modified: 2010-04-16
When I run my app on WinXP w/SP1. CreateProcess doesn't allow the launch
handle to inheirt the the handles.

*I have not tried it on xp w/sp2

This works on Win2k, Win98se.

If it is I have to set the sececurity for it.
Then I have and it still doesn't get the handle.

In the msdn it said it changed the way the security is done with createprocess on winxp w/sp2 and w2003, but
doesn't exaplain exactly what it changed.  Which lead me to try to include the @security, but it still doesn't work
with that.

Does anyone know which Windows Update might of affectted this, because as of April of this year this code was working
on WinXP w/SP1.

Delphi v6 w/all updates

code-
     FillChar(FossilPI, sizeof(TProcessInformation), 0);
     FillChar(FossilSI, SizeOf(TStartupInfo), 0);
     FossilSI.cb := SizeOf(TStartupInfo);
     FossilSI.dwFlags := STARTF_USESHOWWINDOW;
     FossilSI.wShowWindow := SW_NORMAL;

     AppPath := 'C:\RG\';
     AppParams := ExtractFilePath(ParamStr(0)) + 'mSyncFos.exe 1 '+IntToStr(Sock1Handle)+' 100 C:\RG\RENEGADE.EXE -N1 -B19200 -T -Q';

    InitializeSecurityDescriptor(@SecDes, 1);
    SetSecurityDescriptorDacl(@secDes, True, nil, False);

    With Security do begin
       nlength := SizeOf(TSecurityAttributes) ;
       binherithandle := true;
       lpsecuritydescriptor := @SecDes;
    end;       }


                                                    //@Security, @Security
    if CreateProcess(nil, PChar(AppParams), nil, nil, true, NORMAL_PRIORITY_CLASS, nil, PChar(AppPath), FossilSI, FossilPI) then begin
       repeat
         FossilRS := WaitForSingleObject(FossilPI.hProcess, 1000);
       until FossilRS <> WAIT_TIMEOUT;
        CloseHandle(Fossilpi.hProcess);
        CloseHandle(Fossilpi.hThread);
    end;
end code
 
0
Question by:RenegadeBBS
    7 Comments
     
    LVL 26

    Expert Comment

    by:Russell Libby
    Have you tried using either of the following?

    - GetHandleInformation to see if the handle is actually set to be inherited. On non NT systems, the inheritance is totally ignored, and all open handles are inherited by the child process, regardless of the security attributes.

    - SetHandleInformation to make sure that the HANDLE_FLAG_INHERIT is set.

    Just some ideas...

    Regards,
    Russell
    0
     
    LVL 1

    Author Comment

    by:RenegadeBBS
    No, that didn't work.  I doubt that I will get anymore post upon the subject since the low points I am offering.  I thought I wouldn't be the only one programming delphi that might be getting this error, but it seems as I might be.

    I will be asking for a refund on the question, because I don't know the answer and I don't think I will get any posts to help overcome this.
    0
     
    LVL 26

    Expert Comment

    by:Russell Libby

    Well, I would have been willing to help further (even considering the points), but if the asker wishes to close the q, then that's ok.

    Russell
    0
     
    LVL 1

    Author Comment

    by:RenegadeBBS
    Admin:  I take back the request for a refund on this question.

    rlibby: I'll post a url to the complete code base if you want to take a look at it.

    delphi 6
    www.renegadebbs.net/temp/vrlite.zip
    0
     
    LVL 26

    Accepted Solution

    by:
    The following seems to be working fine for me, as the console app is able to read the data that I write on the inherited socket. I am running WinXP pro/ sp1

    Russell

    ------

      AcceptSock:=Winsock.Accept(ListenSock, @SA, @SizeSA);

      // Check accept result
      if (AcceptSock = Invalid_Socket) then

         // Bail
         exit

      else
      begin

         //uncomment for win95,98,98se,ME
         //works for win95 thru WinME                                                     //ignored                  //why it is ignored

         if not(DuplicateHandle(GetCurrentProcess, AcceptSock, GetCurrentProcess, @PassedSock, DUPLICATE_SAME_ACCESS, True, DUPLICATE_SAME_ACCESS)) then

            // Raise
            RaiseLastWin32Error

         else
         begin

            // Udpate the sys file
            door32sys:=TStringList.Create;
            try
               door32sys.LoadFromFile('c:\code\vrlite\door32.sys');
               door32sys.Strings[1]:=IntToStr(PassedSock);
               door32sys.SaveToFile('c:\code\vrlite\door32.sys');
            finally
               door32sys.Free;
            end;

            // Info on how to load the game
            AppPath:='C:\CODE\VRLITE\MANNIRC';
            AppParams:='C:\CODE\VRLITE\MANNIRC\MANNIRC.EXE -DC:\CODE\VRLITE\DOOR32.SYS';

            // Setting up the processinfo.. Will be filled by createprocess
            FillChar(FossilPI, SizeOf(TProcessInformation), 0);

            // Setting up the windows and how it looks
            FillChar(FossilSI, SizeOf(TStartupInfo), 0);
            FossilSI.cb:=SizeOf(TStartupInfo);
            FossilSI.dwFlags:=STARTF_USESHOWWINDOW;
            FossilSI.wShowWindow:=SW_NORMAL;

            // Check inheritence for PassedSock
            if GetHandleInformation(PassedSock, HandleState) then
            begin
               // Check state
               if not((HandleState and HANDLE_FLAG_INHERIT) =  HANDLE_FLAG_INHERIT) then
               begin
                  // Set inherit flag
                  if not(SetHandleInformation(PassedSock, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) then
                     // Raise
                     RaiseLastWin32Error;
               end;
            end
            else
               // Raise
               RaiseLastWin32Error;

            // Create null security descriptor
            InitializeSecurityDescriptor(@SecDes, SECURITY_DESCRIPTOR_REVISION);
            SetSecurityDescriptorDacl(@secDes, True, nil, False);

            // Set security attributes
            Security.nLength:=SizeOf(TSecurityAttributes);
            Security.lpSecurityDescriptor:=@SecDes;
            Security.bInheritHandle:=True;

            if CreateProcess(nil, PChar(AppParams), @Security, @Security, True, NORMAL_PRIORITY_CLASS, nil, PChar(AppPath), FossilSI, FossilPI) then
            begin
               // Wait for process to complete
               while (WaitForSingleObject(FossilPI.hProcess, 50) = WAIT_TIMEOUT) do;
               // Cleaning up createprocess
               CloseHandle(Fossilpi.hProcess);
               CloseHandle(Fossilpi.hThread);
            end;

            // Cleaning up the socket & socket handles made.
            Winsock.Shutdown(AcceptSock, 2);
            Winsock.CloseSocket(AcceptSock);

            Winsock.Shutdown(PassedSock, 2);
            Winsock.CloseSocket(PassedSock);

         end;
      end;
    0
     
    LVL 1

    Author Comment

    by:RenegadeBBS

    After tring the code and it not working for me yet again!! I startted to look over my conf and see what exactly was causing this on my computer.

    QoS: Quality of Service.  After Uninstalling QoS from the network protocols it works!  Seems as though QoS was
    intterupting sockets and stuff.  eww!

    rllibby: I am getting a refund on a couple of other questions in about two day's.  As soon as those go through I will add points to the question and give them to you for your help.

    0
     
    LVL 1

    Author Comment

    by:RenegadeBBS
    So, it was more of a Sockets issue then the CreateProcess letting the handle to be inhierited issue.

    I alsouninstalled also.. .net frameworks, j# frame works, and a few .net componet frame works.  Don't know if that could have affectted it also.  I guess I could reinstall QoS and see if it doesn't work after I do that.

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    933 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

    16 Experts available now in Live!

    Get 1:1 Help Now