Loading ...
Sorry, an error occurred while loading the content.

Re: [BATCH WORLD] set environment

Expand Messages
  • foxidrive
    ... So I arranged it so it would set the variable to OfcPfwSvc as per your example output. Tell me what you need to do. On Wed, 22 Aug 2007 06:42:06 -0700
    Message 1 of 7 , Aug 22, 2007
    • 0 Attachment
      Please be a little clearer in what you want. You stated:

      > Now i want to set OfcPfwSvc or any line above RUNNING as my %Dep%

      So I arranged it so it would set the variable to OfcPfwSvc as per your
      example output. Tell me what you need to do.




      On Wed, 22 Aug 2007 06:42:06 -0700 (PDT), Raja Sekhar <rajasn@...>
      wrote:

      >Hi Foxidrive ,
      > here is my complete batchfile
      > When run this i get, but i want only the running one , with this batchfile it always restarts the second one in the list .
      >
      > C:\scripts>sc EnumDepend winmgmt | findstr /i "SERVICE_NAME RUNNING"
      >SERVICE_NAME: SharedAccess
      >SERVICE_NAME: OfcPfwSvc
      > STATE : 4 RUNNING
      >
      > C:\scripts>for /f "tokens=2" %B in ('sc EnumDepend winmgmt^|findstr /i "SERVICE_
      >NAME RUNNING"^|FIND "SERVICE_NAME"') do set Dep=%B
      > C:\scripts>set Dep=SharedAccess
      > C:\scripts>set Dep=OfcPfwSvc
      >
      > @echo on
      >for /f %%B in ('sc EnumDepend winmgmt^|find /c "RUNNING"') do set entries=%%B
      >if /i %entries% GTR 1 goto moreentries
      >goto next
      > :next
      >for /f "tokens=2" %%B in ('sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME RUNNING"^|FIND "SERVICE_NAME"') do set Dep=%%B
      >echo "%Dep%"
      >net stop "Windows Management Instrumentation" /y
      >net start "Windows Management Instrumentation"
      >net start "%Dep%"
      >echo DONE !!!
      >goto End
      > :moreentries
      >echo.
      >echo Found more than 1 Dependent Service Running,
      >echo Please restart the WMI Service Manually
      >goto End
      > :End
      >
      > Thanks,
      >Raja Sekhar
      >
      >foxidrive <foxidrive@...> wrote:
      > On Wed, 22 Aug 2007 05:10:17 -0700 (PDT), Raja Sekhar <rajasn@...>
      >wrote:
      >
      >>Hi,
      >>
      >> When i do run sc EnumDepend winmgmt |findstr /i "SERVICE_NAME RUNNING"
      >> i get
      >>
      >> SERVICE_NAME: SharedAccess
      >>SERVICE_NAME: OfcPfwSvc
      >> STATE : 4 RUNNING
      >>
      >> Now i want to set OfcPfwSvc or any line above RUNNING as my %Dep%.I just need to set above line Second word from RUNNING %Dep%.If there are more than one RUNNING i am quitting so that is not a issue
      >>
      >> i am stuck at this point , any help thanks in advance
      >>
      >
      >Untested:
      >
      >for /f "tokens=2" %%B in (
      >'sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME RUNNING"^|FIND
      >"SERVICE_NAME"') do set Dep=%%B
      >
      >
    • Raja Sekhar
      I want the Running Service name as %Dep% for example if SharedAccess was Running i would get SERVICE_NAME: SharedAccess STATE : 4 RUNNING
      Message 2 of 7 , Aug 22, 2007
      • 0 Attachment
        I want the Running Service name as %Dep%
        for example if SharedAccess was Running i would get

        SERVICE_NAME: SharedAccess
        STATE : 4 RUNNING
        SERVICE_NAME: OfcPfwSvc

        so i want which ever service is running ( SharedAccess or OfcPfwsvc ) as %Dep%
        Now as OfcPfwSvc is Running i get as

        SERVICE_NAME: SharedAccess
        SERVICE_NAME: OfcPfwSvc
        STATE : 4 RUNNING

        Sorry if i have confused you.

        Raja Sekhar


        foxidrive <foxidrive@...> wrote:

        Please be a little clearer in what you want. You stated:

        > Now i want to set OfcPfwSvc or any line above RUNNING as my %Dep%

        So I arranged it so it would set the variable to OfcPfwSvc as per your
        example output. Tell me what you need to do.

        On Wed, 22 Aug 2007 06:42:06 -0700 (PDT), Raja Sekhar <rajasn@...>
        wrote:

        >Hi Foxidrive ,
        > here is my complete batchfile
        > When run this i get, but i want only the running one , with this batchfile it always restarts the second one in the list .
        >
        > C:\scripts>sc EnumDepend winmgmt | findstr /i "SERVICE_NAME RUNNING"
        >SERVICE_NAME: SharedAccess
        >SERVICE_NAME: OfcPfwSvc
        > STATE : 4 RUNNING
        >
        > C:\scripts>for /f "tokens=2" %B in ('sc EnumDepend winmgmt^|findstr /i "SERVICE_
        >NAME RUNNING"^|FIND "SERVICE_NAME"') do set Dep=%B
        > C:\scripts>set Dep=SharedAccess
        > C:\scripts>set Dep=OfcPfwSvc
        >
        > @echo on
        >for /f %%B in ('sc EnumDepend winmgmt^|find /c "RUNNING"') do set entries=%%B
        >if /i %entries% GTR 1 goto moreentries
        >goto next
        > :next
        >for /f "tokens=2" %%B in ('sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME RUNNING"^|FIND "SERVICE_NAME"') do set Dep=%%B
        >echo "%Dep%"
        >net stop "Windows Management Instrumentation" /y
        >net start "Windows Management Instrumentation"
        >net start "%Dep%"
        >echo DONE !!!
        >goto End
        > :moreentries
        >echo.
        >echo Found more than 1 Dependent Service Running,
        >echo Please restart the WMI Service Manually
        >goto End
        > :End
        >
        > Thanks,
        >Raja Sekhar
        >
        >foxidrive <foxidrive@...> wrote:
        > On Wed, 22 Aug 2007 05:10:17 -0700 (PDT), Raja Sekhar <rajasn@...>
        >wrote:
        >
        >>Hi,
        >>
        >> When i do run sc EnumDepend winmgmt |findstr /i "SERVICE_NAME RUNNING"
        >> i get
        >>
        >> SERVICE_NAME: SharedAccess
        >>SERVICE_NAME: OfcPfwSvc
        >> STATE : 4 RUNNING
        >>
        >> Now i want to set OfcPfwSvc or any line above RUNNING as my %Dep%.I just need to set above line Second word from RUNNING %Dep%.If there are more than one RUNNING i am quitting so that is not a issue
        >>
        >> i am stuck at this point , any help thanks in advance
        >>
        >
        >Untested:
        >
        >for /f "tokens=2" %%B in (
        >'sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME RUNNING"^|FIND
        >"SERVICE_NAME"') do set Dep=%%B
        >
        >






        ---------------------------------
        Luggage? GPS? Comic books?
        Check out fitting gifts for grads at Yahoo! Search.

        [Non-text portions of this message have been removed]
      • foxidrive
        On Wed, 22 Aug 2007 07:11:18 -0700 (PDT), Raja Sekhar ... This sets the variable to the 2nd token, and on subsequent passes checks if the
        Message 3 of 7 , Aug 22, 2007
        • 0 Attachment
          On Wed, 22 Aug 2007 07:11:18 -0700 (PDT), Raja Sekhar <rajasn@...>
          wrote:

          >
          >I want the Running Service name as %Dep%
          > for example if SharedAccess was Running i would get
          >
          > SERVICE_NAME: SharedAccess
          > STATE : 4 RUNNING
          >SERVICE_NAME: OfcPfwSvc
          >
          > so i want which ever service is running ( SharedAccess or OfcPfwsvc ) as %Dep%
          > Now as OfcPfwSvc is Running i get as
          >
          > SERVICE_NAME: SharedAccess
          > SERVICE_NAME: OfcPfwSvc
          > STATE : 4 RUNNING
          >
          > Sorry if i have confused you.
          >
          > Raja Sekhar

          This sets the variable to the 2nd token, and on subsequent passes checks if
          the "STATE : number RUNNING" line is encountered when the 2nd token is :
          when it will branch out of the loop.

          @echo off
          for /f "tokens=2" %%B in (
          'sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME RUNNING"'
          ) do (
          if %%B.==:. goto :next
          set Dep=%%B
          )
          :next
          echo %dep%
        • Raja Sekhar
          Thank You foxidrive, works perfectly Raja Sekhar ... ____________________________________________________________________________________Ready for the edge of
          Message 4 of 7 , Aug 22, 2007
          • 0 Attachment
            Thank You foxidrive, works perfectly

            Raja Sekhar

            --- foxidrive <foxidrive@...> wrote:

            > On Wed, 22 Aug 2007 07:11:18 -0700 (PDT), Raja
            > Sekhar <rajasn@...>
            > wrote:
            >
            > >
            > >I want the Running Service name as %Dep%
            > > for example if SharedAccess was Running i would
            > get
            > >
            > > SERVICE_NAME: SharedAccess
            > > STATE : 4 RUNNING
            > >SERVICE_NAME: OfcPfwSvc
            > >
            > > so i want which ever service is running (
            > SharedAccess or OfcPfwsvc ) as %Dep%
            > > Now as OfcPfwSvc is Running i get as
            > >
            > > SERVICE_NAME: SharedAccess
            > > SERVICE_NAME: OfcPfwSvc
            > > STATE : 4 RUNNING
            > >
            > > Sorry if i have confused you.
            > >
            > > Raja Sekhar
            >
            > This sets the variable to the 2nd token, and on
            > subsequent passes checks if
            > the "STATE : number RUNNING" line is encountered
            > when the 2nd token is :
            > when it will branch out of the loop.
            >
            > @echo off
            > for /f "tokens=2" %%B in (
            > 'sc EnumDepend winmgmt^|findstr /i "SERVICE_NAME
            > RUNNING"'
            > ) do (
            > if %%B.==:. goto :next
            > set Dep=%%B
            > )
            > :next
            > echo %dep%
            >
            >
            >
            >




            ____________________________________________________________________________________Ready for the edge of your seat?
            Check out tonight's top picks on Yahoo! TV.
            http://tv.yahoo.com/
          Your message has been successfully submitted and would be delivered to recipients shortly.