[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CreateProcess( not inhiert handle not working

Posted on 2004-10-26
8
Medium Priority
?
518 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
Comment
Question by:RenegadeBBS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 12412069
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
ID: 12465051
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
ID: 12465443

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:RenegadeBBS
ID: 12471681
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:
Russell Libby earned 615 total points
ID: 12473782
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
ID: 12480240

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
ID: 12480251
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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