Running External Process from service

This is a discussion on Running External Process from service within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, I'm having trouble running an external process (CreateProcess) from a service. WaitForSingleObject fails with a timeout (WAIT_TIMEOUT). The ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    Running External Process from service

    Hi All,

    I'm having trouble running an external process (CreateProcess) from a service. WaitForSingleObject fails with a timeout (WAIT_TIMEOUT).

    The same code is actually called twice - so I know the code works - firstly for winrar (which works) and then for pscp (which fails with the timeout).

    If I run the code directly (not from a service) it works OK.

    I'm using absolute paths, so I know this isn't the issue (because sevices run from system32).

    What other factor cause cause this? What else could the service be doing to cause this?

    I can post the code and the full pscp command I'm using if required but this seems to be an issue with something the 'service' is doing.

    Thanks for any help, rotis23

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    Are you checking for error conditions on all your API calls? Does task manager show pscp running?

    You may be having problems because pscp is a console application. Try setting up your service to "Allow interaction with desktop".

    gg

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Thanks for your comments Codeplug.

    It turned out to be because of user interaction required by pscp (even though I was using -batch switch).

    Services run as local.system and because I was using ssh keys with pscp, pscp wanted to get confirmation from the user to store the ssl session. This meant that the service hung waiting for user input and waitforsingleobject caused a timeout. All I need was to say 'Yes' the first time and subsequent scp's would work.

    The solution was a bit of a hack, but I'll share it with you in case anyone know the 'proper' way to do it:

    Because I couldn't login as local.system (not a proper user) I had to find a way of becoming local.system. Someone told me that you can become local.system by running cmd.exe via the at command!! So I did the following:

    - got a command prompt
    - ran the following at command

    at 12:30 "c:\winnt\system32\cmd.exe"

    - this gave me a command prompt for local.system

    - I then ran the scp command manually and answered 'Yes' to store the session

    Phew!

    What the 'proper' way to get round this then?

    rotis23

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check Running Process Dev-C++
    By gamesplant in forum Windows Programming
    Replies: 23
    Last Post: 10-19-2009, 03:20 AM
  2. fork, execv, spawn, or something else?
    By DavidP in forum C++ Programming
    Replies: 8
    Last Post: 01-26-2009, 03:25 PM
  3. How to check if own created process is still running
    By s-men in forum Windows Programming
    Replies: 3
    Last Post: 01-24-2009, 10:39 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. Running external programs
    By speedy in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2001, 05:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21