Force a Service Failure in Windows

Discussion in 'OT Technology' started by 5Gen_Prelude, Aug 14, 2006.

  1. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Anyone know how to force a failure of a service in Windows? I'm testing a script out and I want to make sure the parsing of the command line works but I need a service to fail for it to work.

    IBjustwaitlongenoughandaservicewillfail
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,444
    Likes Received:
    12
    Pick a simple useless service and rename the binary/executable that it calls so it will fail.

    I have no idea, but I'm just throwing this idea in the air.

    I tried it with the telnet server and I got an error 2. Should work if you're capturing the error status other than zero.

    Also be aware that with xp it auto restores the file when it's renamed.

    Or you can create your own service for more control obviously.
     
  3. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Hmmm - that would test a start failure (which would be useful but I seem to be running into that problem without trying to make it fail). I'm now testing a failure when the service is still running.
     
  4. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,444
    Likes Received:
    12
    Hmm, is there a way to send a signal into that service's process then? Killing it won't cause an error?
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    There is a way to kill services that don't need to run inside SvcHost.exe, and that is by issuing a KillProcess(ProcessHandle as long, InstantKill as Boolean) API command. First you have to get the process' handle by tracking its filename down in the list of currently-running processes. I know how to to it in VB (though the code is the same in any Windows-compatible language, on account of using API calls to do the job), and my Advanced Process Scheduler program can do this. A simple script written in my program will kill a process every time it starts; if it's a Service, eventually Windows will give up trying to run it.

    If the service runs inside of SvcHost.exe, it gets harder because you have to know which instance of SvcHost is hosting the Service, and that's a trial-and-error sort of thing.

    Why do you want to do this, again?
     
  6. EvilSS

    EvilSS New Member

    Joined:
    Jun 11, 2003
    Messages:
    5,104
    Likes Received:
    0
    Location:
    STL
    Open taskmanager, kill process. If it's running under svchost, use SysInternals Process Explorer to find it and kill it (free utility).
     
  7. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I'm not trying to kill a process - I'm trying to make a service go into the shitter while running. Why? Because I'm testing the recovery of a failed service within services. I've written a script that will handle, log and email the error but I need to make sure the command parameters its passing actually do work - I can't do that until the script is triggered and executed by windows.
     
  8. EvilSS

    EvilSS New Member

    Joined:
    Jun 11, 2003
    Messages:
    5,104
    Likes Received:
    0
    Location:
    STL
    Yes, I know what you are trying to do. Killing the process will trip the autorecovery.
     
  9. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well SoB. I tried it again with another service (SmartCard) and it did indeed fail when ending that process. Can't remember which process I killed before but it didn't trigger anything.

    Thanks all
     

Share This Page