?
Solved

CreateProcess( not inhiert handle not working

Posted on 2004-10-26
8
Medium Priority
?
525 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
  • 4
  • 3
7 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

588 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