Forum Discussion

avenedam's avatar
avenedam
Occasional Contributor
14 years ago

Stopping/Starting Windows Service

Hi There!



I'm having a little bit of an issue trying to stop/start/restart a windows service.  I found the article in the FAQ that shows how to do it with vbscript and jscript, but I'm writing my code in C#.  Is there anyone out there that can give me some hints?



Thanks!

5 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Audrey,



    JScript code can be used as it is in the C#/C++-based projects because C# and C++ script languages in TestComplete are actually a syntax-decorated JScript to make it possible to compile test code into real C# or C++ applications. Considering the above, you may consider switching to JScript as it has more simple and clear syntax unless you are going to create a Connected Application (see "Connected Applications" TestComplete help topic for more details).
  • Just a little bit think - use cmd - sc stop / star <<service_name>>
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Nikita,



    This will work indeed. But with one possible problem. ;)

    The case is that 'sc stop' (or 'net stop') returns as soon as the relevant code in the stopped service exits. But depending on the service, the actual process might be running sor some more time. For example, for the Firebird database service the 'net stop' returns quickly, but the processes will be running for quite a long time until all tasks are completed/postponed and database files are closed. In this case I would recommend a loop (with optional timeout) to wait until the service's process is closed.
  • avenedam's avatar
    avenedam
    Occasional Contributor
    Thanks for the help folks!

    I was considering using the net stop/start commands, but wanted something a little more elegant. 



    The jscript code did the trick!