Announcement

Collapse
No announcement yet.

restart services through VBS?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • restart services through VBS?

    Hello,

    I have a 100 citrix servers.
    Lately we're having a problem and any now and then the "IMA" service crushes.
    the only option is to connect to server and restart the service.

    I want to go to the recovery tab and define "restart the service" in all three attempts, but there is no chance I'll go through 100 servers to change it

    Anyway, I'm looking for a script where I can write the service name and run it on all servers.

    Any help will be appreciated.

    10X

    Poly.

  • #2
    Re: restart services through VBS?

    You could use this solution if the imasrv.exe process terminates.

    I have used a similar process for a development application which required the user to be logged in running a java.exe to provide a web service, if the user running java.exe process logged out or the process was terminated the web service became unavailable, as a temporay workaround I created a powershell script which binded to the process, in this case java.exe and when the process was terminated restart the application from the associated bacth file.

    Just create a batch file, containing which ever commands you require to restart your service (taskkill, net stop & net start etc.) and insert the path next to invoke item. I used start-sleep to suspend the command shell to prevent a second instance of the batch file being invoked as the application took approximately 45 seconds to start. You can modify this accordingly or remove id not needed.I then created a scheduled task running as a service account and configured the scheduled task to run on computer startup. The powershell script runs continiously using a loop function.

    This could be used as a temporary workaround but would require a scheduled task creating.

    Code:
    $b = 1
    do
    	{
    $a = get-process ImaSrv
    $a.waitforexit()
    Invoke-Item <batch file>
    start-sleep -s 180
    	}
    while ($b -eq 1)
    MCSA 2000/2003

    Comment


    • #3
      Re: restart services through VBS?

      10x

      but I'm looking for a one time running script that will change the First Failure from Take No Action ---> Restart The Service.

      I don't need any schedule tasks or a script to run whenever the service stops, but to run a script NOW that will change the above parameters. The next time the IMA service will crush it will start the service by itself without me involved...

      Hope I'm understood.

      Comment


      • #4
        Re: restart services through VBS?

        Sorry my mistake.

        Could you not create a .reg file containing the below to restart the service on first failure:

        Code:
        Windows Registry Editor Version 5.00
        
        [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\IMAService]
        "FailureActions"=hex:00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,50,00,43,\
          00,01,00,00,00,60,ea,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
        Then use vbscript to import into the registry using a hard array or excel file specifying your servers/or run agaisnt an organisational unit using Active Directory if your servers are located in the one organisational unit.
        Last edited by themanwhowouldbeking; 6th November 2007, 20:35.
        MCSA 2000/2003

        Comment


        • #5
          Re: restart services through VBS?

          10X

          It's working but only on the first failure.

          I'll use it anyway, BUT - do you know how can I change it to restart the service on second and third failure as well?




          Poly

          Comment


          • #6
            Re: restart services through VBS?

            Try the following:

            Code:
            Windows Registry Editor Version 5.00
            
            [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\IMAService]
            
            
            "FailureActions"=hex:00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,50,00,43,\
              00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00
            MCSA 2000/2003

            Comment


            • #7
              Re: restart services through VBS?

              Originally posted by themanwhowouldbeking View Post
              Try the following:

              Code:
              Windows Registry Editor Version 5.00
              
              [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\IMAService]
              
              
              "FailureActions"=hex:00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,50,00,43,\
                00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00
              This one doesn't even create the registry value...

              Comment


              • #8
                Re: restart services through VBS?

                I did not use the IMA Service as my example, I used a different service from my development workstation. On importing the registry key, the recovery actions where to 'Restart the Service' on first, second and third failure. Open deleting the REG_BINARY key the recovery options where returned to default 'Take No Action'.

                Set the recovery options you require on one server for the IMA Service and then browse to the registry key HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\I MAService and export the REG_BINARY key with the values. Then use this to import test importing registry key.

                The Failure Action in my test scenario worked for numerous services when i just renamed the service reference to the registry key.
                MCSA 2000/2003

                Comment


                • #9
                  Re: restart services through VBS?

                  10X !!!

                  I had to much spaces...

                  It's working great !

                  Comment


                  • #10
                    Re: restart services through VBS?

                    By editing the CurrentControlSet instead of the numbered control sets, you’re assured that the changes are made to whichever control set is currently in force.
                    In the key HKLM\SYSTEM\Select you find information how the present numbered control sets are being used. ControlSet001 doesn't always have to be the Default, or could have failed on this boot.
                    ( http://www.windowsitlibrary.com/Content/405/11/3.html )


                    --------------------------

                    Just a thought, (?)Maybe you can copy this batch to each server
                    Code:
                    @echo off
                    Set fCnt=%1 %2 %3 %3 %4
                    
                    %comspec% /c SC.exe stop IMAService &&start/b/w NET.exe start IMAService
                    
                    :: Create datestamp variable
                      echo. | date | FIND "(mm" > NUL
                      If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
                      goto :EOF
                     :Parsedate ----------------------------------------------------------
                      For /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
                         set %1=0%%A&set %2=0%%B&set YYYY=%%C
                       ) else (
                         set DOW=%%A&set %1=0%%B&set %2=0%%C&set YYYY=%%D)
                      (Set MM=%MM:~-2%) ||:>   in the For-Do loop I added an extra 0 to these variables (just in case)   
                      (Set DD=%DD:~-2%) ||:>   now both variables are trimmed to two characters again.
                      (Set DateStamp=%YYYY%%MM%%DD%)
                    
                    echo:%time% %fCnt%>>"c:\IMAService-%DateStamp%.log"
                    Then on one server, in the the properties of the service on the Recovery tab,
                    select; Subsequent failures: Run a program
                    And - append fail count to the commandline: /fail=%1%
                    Export the service regkey

                    \Rems

                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    __________________

                    ** Remember to give credit where credit's due **
                    and leave Reputation Points for meaningful posts

                    Comment


                    • #11
                      Re: restart services through VBS?

                      10x, but your request requires me ro log on to each server and change parameters by myself and not automated, which kind of misses the whole purpose of my first thread...

                      Comment


                      • #12
                        Re: restart services through VBS?

                        requires me to log on to each server and change parameters by myself and not automated
                        No that is not true,
                        it is still exact the same situation as ;
                        Originally posted by themanwhowouldbeking View Post
                        Set the recovery options you require on one server for the IMA Service and then browse to the registry key HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\IMAService and export the REG_BINARY key with the values. Then use this to import test importing registry key.
                        I just suggested to use the 'CurrentControlSet' key path here.

                        optional:
                        I you want to try "Run a program" on failure. There just will be one extra entry in the regkey of that service: "FailureCommand". The value is the path to the batch to run. If you export the key for distribution, you export also the new Item. The only thing you have to do else is to copy the batch to the corresponding path on the servers. You can do it all with one script.

                        \Rems

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment

                        Working...
                        X