Force a service to restart or run without admin privileged?

Discussion in 'Windows Server' started by ToddAndMargo, Jan 7, 2010.

  1. ToddAndMargo

    ToddAndMargo Guest

    Hi All,

    I have a WS08 Terminal Service running as a Virtual

    There is a service I need to have running that
    only likes to run if it sees a program it is associate
    with. It the service does not see its favorite
    program after a certain delay period, it stops. No
    problem (usually): when the program starts, it will
    restart the service.

    Problem: the service requires Windows Admin privileged,
    which I do not give to the users, so the program can
    not start the service.

    I have set the services recovery tab to restart,
    but the service eventually outsmarts the recovery

    Is there:

    1) a way to force the service to constantly restart
    regardless of what it wants to do? and/or

    2) a way to give the service the ability to start
    without Windows Admin privileges so the the program
    can start it without a UAC?

    Many thanks,
    ToddAndMargo, Jan 7, 2010
    1. Advertisements

  2. You can create a scheduled task that runs under the System account once
    every x minutes. It runs the following batch file:

    sc query "NameOfService" | find /i "running" || sc start "NameOfService

    A more elegant way would be to use WMI to monitor the service and restart it
    automatically whenever it goes down. I'm not very fond of WMI processes as
    they can gobble up a lot of background CPU time but if you wish to explore
    this option then I'll knock together a script for you.
    Pegasus [MVP], Jan 7, 2010
    1. Advertisements

  3. ToddAndMargo

    ToddAndMargo Guest

    I like it. Thank you!

    What does the double pipe ("||") do?

    I will fully torture the scheduled task first.

    ToddAndMargo, Jan 8, 2010
  4. The command processor knows the following connectors:
    |: Pipe the output from one command into another command.
    &: Run two commands with a single command line, e.g.
    copy x.txt y.txt & copy a.dat b.dat
    ||: Run the command to the right only if ErrorLevel > 0
    copy x.txt z.txt || echo Error!
    &&: Run the command to the right only if ErrorLevel = 0
    copy x.txt z.txt && echo Success!

    In your case the first instance of sc.exe will query the state of your
    service. Its output is piped into find.exe, which searches for the word
    "running". If it cannot find it then it will terminate with an ErrorLevel >
    0, which will cause the second instance of sc.exe to execute.
    Pegasus [MVP], Jan 8, 2010
  5. ToddAndMargo

    ToddAndMargo Guest

    I have been writing batch files for years and did not
    realize I had this functionality. Thank you!

    p.s. I copied and pasted it into my list of "batch"
    helper files.
    ToddAndMargo, Jan 9, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.