CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: CreateProcess

  1. #1
    Join Date
    Feb 2007
    Posts
    102

    CreateProcess

    Hi,

    I am having difficulties with the CreateProcess function.
    I have developed a server application that can receive images from a socket. If the received images are not compressed, I want to compress them before storing them on the hard drive. The problem is that some of images make the compression function crash. I don't have access to the function so I can't debug it. So the idea would be for each received image, to create a separated process that will compress the image. If the process crashes, I will store the image in raw format.

    The problem is that my server is running as a service in the local system account. The CreateProcess function always fail in that case. I tried to use CreateProcessAsUser instead but I was not successful either. Does someone know how to create a new process from a service application that runs in the local system account? The new process I want to start has no window and does not need to interact with the background.

    Thank you for your time,

    madric

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    I am having difficulties with the CreateProcess function.
    I have developed a server application that can receive images from a socket. If the received images are not compressed, I want to compress them before storing them on the hard drive. The problem is that some of images make the compression function crash. I don't have access to the function so I can't debug it. So the idea would be for each received image, to create a separated process that will compress the image. If the process crashes, I will store the image in raw format.
    Or you could just drop whichever buggy image library you are using and swap it for one that works.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Feb 2007
    Posts
    102

    Re: CreateProcess

    Can't do that

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    I don't have access to the function so I can't debug it.
    I think you should give us more information on this function you say crashes. Who created this function? Have you contacted them? Do you have a suite of images you know crash this compression function?
    The problem is that my server is running as a service in the local system account. The CreateProcess function always fail in that case. I tried to use CreateProcessAsUser instead but I was not successful either. Does someone know how to create a new process from a service application that runs in the local system account? The new process I want to start has no window and does not need to interact with the background.
    Wouldn't it be just as easy, if not easier, to use free libraries like zlib or gzip to compress the images yourself? There has to be hundreds, if not thousands of examples showing usage of these libraries.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Feb 2007
    Posts
    102

    Re: CreateProcess

    humm, this is what I was afraid about. Everybody will not try to explain me how to create a new process from a program that runs as a service. Which was my question and a general problem anyway that many people have from what I can find on the internet. For the record, I am already using free libraries (dcmtk and independant Jpeg libraries). However, the images are in DICOM format and it would take me too much time to try to debug them. Creating a separated process is a simple and quick way.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    For the record, I am already using free libraries (dcmtk and independant Jpeg libraries). However, the images are in DICOM format and it would take me too much time to try to debug them.
    It doesn't matter what format the images are in. A library such as zlib just compresses streams. There is no need to debug anything.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    The problem is that my server is running as a service in the local system account. The CreateProcess function always fail in that case. I tried to use CreateProcessAsUser instead but I was not successful either. Does someone know how to create a new process from a service application that runs in the local system account? The new process I want to start has no window and does not need to interact with the background.
    Show us the precise code by which you are calling CreateProcess (remember to use [ code ] tags for formatting).

    Tell us what GetLastError returns when the call to CreateProcess fails.

    Show us the same things for your attempt to use CreateProcessAsUser.

    Mike

  8. #8
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CreateProcess

    And if your problem is being caused by UAC issues, then I came across the following snippet at http://social.msdn.microsoft.com/For...9-77d82875554d
    Code:
    TOKEN_LINKED_TOKEN linkedToken = {0};
    
    dwSize = sizeof(linkedToken);
    
    // Get the linked token
    
    if (GetTokenInformation(hToken, TokenLinkedToken, &linkedToken, dwSize, &dwSize))
    {
       // The linked token is not a primary token, so we create one from it.
    
       if (DuplicateTokenEx(linkedToken.LinkedToken, MAXIMUM_ALLOWED, NULL, 
          SecurityImpersonation, TokenPrimary, &hPrimaryToken)) 
       {
          CreateProcessAsUser(hPrimaryToken,…);
       }
    }
    Personally, I would put in a bunch of GetLastError's, and display the results with TRACE or OutputDebugString.

    Mike

  9. #9
    Join Date
    Feb 2007
    Posts
    102

    Re: CreateProcess

    Hi,

    Thank you all for your interest in my problem.
    I finally solved it.

    My CreateProcess function was calling my console application "Compression.exe" with some parameters. When the "Compression.exe" is compiled using MFC in shared DLL, the CreateProcess always failed (the error message was asking me to reinstall the program). If it is compiled using MFC in a static library, it works like a charm. This happens only if I call CreateProcess from a service application.

    Now, I have a second problem. On purpose, I make my "Compression.exe" crashes in the middle of its execution. After the call of CreateProcess, I am waiting the end of execution of my "Compression.exe" program. But it never ends. I suspect that the crash generates dialog window on screen but since it is called from a service application (in the local system account), it can't display any message on screen.
    Is there a way to make the application crashed silently, without any message? Or is there another reason?

    Regards,

    madric

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    Is there a way to make the application crashed silently, without any message?
    Sorry to say, but I knew this was going to happen. I was going to additionally mention this to you -- you should not be depending on how bad a program crashes.

    A third-party program crash is not under your control -- you even stated you can't change the program. That's why I stated to use a library in your program, or if you really want to call CreateProcess, create a non-crashable compression program based on thoroughly tested libraries, i.e. zlib. It isn't that hard to do -- you would have had it done in the 1 or 2 days you had posted your original problem.

    As to how you bypass the dialog, you have to change the program that crashes to do that, and you claim you can't do that. That would require the usage of an SE handler in the application to bypass the display of the crash dialog and terminate the application (this is usually done to create crash dumps). But the bottom line is that you shouldn't base your workflow on the state of a buggy program that crashes, especially when there are easy solutions that bypasses this whole scenario.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 30th, 2012 at 01:53 AM.

  11. #11
    Join Date
    Feb 2007
    Posts
    102

    Re: CreateProcess

    I am sorry, but I disagree with you. I am not working in a perfect environment with perfect program and perfect images. The libraries I am using are open source libraries. Ok, if I will follow your advise, please tell me how I can replace DCMTK with another free library in 2 days?

    There is a difference between a buggy library in a robust library. A library can be bug-less but will crash if you give wrong data as input. The library is just not super robust. Now, my input are DICOM images that have some tags that are not correct to compress the image. Now, my doctors don't care if the images are correct or not. They want to see them, that's all. Telling them that they should ask the maker of the images to modify them is absolutely not an option (I just can report the problem). My doctors can see the image with other softwares that don't compress the images and can't understand why they can't see them with mine. Just my software is bad, their logic stop here. And this is a reality in the business.

    Using a separated process for compressing the images without risking to compromise the server is one way to make it more robust. Now, I have to find out if I can detect that a processus has crashed or not.

  12. #12
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    I am sorry, but I disagree with you. I am not working in a perfect environment with perfect program and perfect images. The libraries I am using are open source libraries. Ok, if I will follow your advise, please tell me how I can replace DCMTK with another free library in 2 days?
    I gave you one library, zlib. I also stated that it doesn't matter what the image file is. The zlib compresses any type of file, similar to WinZip or gzip.

    Did you go to the zlib site?

    http://zlib.net/
    http://zlib.net/zlib_how.html
    http://zlib.net/zpipe.c

    In the last link is an entire program that compresses an input file to an output file. Just replace stdin and stdout with the input and output file handles.
    There is a difference between a buggy library in a robust library. A library can be bug-less but will crash if you give wrong data as input.
    That is not a bug-less library. The library is supposed to check for bad input. No software should crash on bad input. If it does, then that is a hole in the program that needs to be corrected. Either the bad input is supposed to be detected, or the worse case is to do as I stated in the previous post -- the application has an SE handler that gets called that handles the crash.

    Take a simple example -- a program that computes square roots. Should it crash because the data sent to it is a negative number? How about a program that attempts to divide by 0, assuming that 0 was the input given to it. Is that a bug-less program? Maybe the program you are running now is crashing on such a scenario.

    My company produces software libraries -- any crash, even on invalid data, is looked at and corrected to make sure that the bad data doesn't get through.
    Now, my doctors don't care if the images are correct or not. They want to see them, that's all. Telling them that they should ask the maker of the images to modify them is absolutely not an option (I just can report the problem).
    Again, I am not asking for the images to be modified. Please read my post carefully and read what zlib does. It takes whatever the input is, compresses it, and you have a new compressed file. It could be a BMP file, a text file, an image file, a movie file, an Excel spreadsheet, it doesn't matter.

    If not zlib, there is gzip. Both of these libraries are well-known, used in thousands of applications, and for the case of gzip, is a mainstay in the Unix world (with ports to Windows). For zlib, this is the compression used by Adobe within PDF data streams. But again, these are general purpose compression libraries. Mentioning you have to change image types or formats doesn't come into play at all here.

    Gzip:

    http://www.gzip.org/

    There is an executable already created that compresses / decompresses. All you had to do was call CreateProcess() to invoke gzip/gunzip with the appropriate parameters.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 30th, 2012 at 04:07 AM.

  13. #13
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess

    Quote Originally Posted by madric View Post
    Now, my input are DICOM images that have some tags that are not correct to compress the image. Now, my doctors don't care if the images are correct or not. They want to see them, that's all.
    If you took the uncompressed, untouched, DICOM image that has the bad tags, and attempted to display it in whatever viewer program your customer is using, will he/she see the image?

    If they can see the image, and you want to store the compressed version as a file, then you could have used gzip to compress the image (this is the version that is saved to a file), and on viewing, gunzip to do the decompression of the image file before sending it to the viewer program.

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Feb 2007
    Posts
    102

    Re: CreateProcess

    humm, there is misunderstanding about the compression. I don't want to compress the image in a zip folder. I have raw image that I need to compress in Jpeg2K or Jpeg. Those images are not just rgb images but 12 or 16 bits grayscale images.

    I agree that the border between bug-free and robust can be thin. However, besides your simple examples (like the square root) that are very easy to be bug-free and robust, it can be hard to be robust in all cases with much more complex programs. DICOM images have thousand of different tags that can be interpreted differently depending on the modality (MRI, PET scan, CR) that generates the images. I don't know any complex library that is totally bug free (or robust if you like).

    "My company produces software libraries -- any crash, even on invalid data, is looked at and corrected to make sure that the bad data doesn't get through."

    Okay, this means that your libraries are not totally robust if you need to fix them sometimes. When can you assert that your libraries won't crash any more (I am not talking about a square root)? All softwares and libraries have updates regularly that fix the new discovered problems.

    I just found the problem of my image. The maker (a big name) added a private tag that contains an icon of the image. The icon is encoded with a different encoding (raw data for the image and JPEG for the icon) without any information about the encoding type of the icon. When the library compresses the image to JPEG format, it crashes when it process the icon. I can report the problem to the maker of the library, but it will take times, maybe month before getting a fixed version (if there is any). How am I supposed to do since the doctor want to see the image tomorrow? I can't tell him that I have to wait for a fix. He wants the image to be compressed and see it perfectly as well. I can't wait unfortunately.

    Anyway, I share your point of view of what libraries and program should be but sometimes, for economic reason, it can't be perfect...

  15. #15
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: CreateProcess

    Let's look at your proplem from a different angle.
    You are already prepared to use differnt viewers for the images.( some images would be converted to jpegs, the ones that fail to convert would have to be viewed in raw format ).
    Using zip compression generally would only mean that you have to provide a simple batch script on the client side that uncompersses the image to raw format before calling the viewer for raw images.
    The only reason why you wouldn't want to do that is that jpegs compress better (when set to low quality) then using the zip algo on raw images.
    If your concern is about diskspace then the question is the percentage of images that fail to convert.
    Kurt

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured