Guest Thomas M. Posted May 29, 2008 Posted May 29, 2008 XP SP2 I'm trying to create a little batch file that will list all the dependencies for a given service. I found the following command on a Web site: FOR /F "TOKENS=*" %s in ('DependOnService <Service Name>') do @echo %s I have replaced the "<Service Name" wit "Spooler, but the command does not work. Instead, it just tells me that DependOnService could not be found. Can anyone tell me how to get this working in a simple batch file? --Tom
Guest VanguardLH Posted May 30, 2008 Posted May 30, 2008 Re: DependOnService "Thomas M." wrote in <news:OL8y$eewIHA.4376@TK2MSFTNGP06.phx.gbl>: > XP SP2 > > I'm trying to create a little batch file that will list all the dependencies > for a given service. I found the following command on a Web site: > > FOR /F "TOKENS=*" %s in ('DependOnService <Service Name>') do @echo %s > > I have replaced the "<Service Name" wit "Spooler, but the command does not > work. Instead, it just tells me that DependOnService could not be found. > > Can anyone tell me how to get this working in a simple batch file? > > --Tom > Where are you getting the string (in the parenthesis) that you are searching through? Looks to me that you simply have a static string so whatever you put there is all that can be parsed by the tokens parameter. Run "sc /?" from a DOS shell. You'll have to redirect the output to a file and then read the file to search for the info. Make sure when using the 'query' directive that you include the trailing space after the equals sign.
Guest Thomas M. Posted May 30, 2008 Posted May 30, 2008 Re: DependOnService "VanguardLH" <V@nguard.LH> wrote in message news:O5KdnRaSP9vc-aLVnZ2dnUVZ_hudnZ2d@comcast.com... > "Thomas M." wrote in <news:OL8y$eewIHA.4376@TK2MSFTNGP06.phx.gbl>: > >> XP SP2 >> >> I'm trying to create a little batch file that will list all the >> dependencies >> for a given service. I found the following command on a Web site: >> >> FOR /F "TOKENS=*" %s in ('DependOnService <Service Name>') do @echo >> %s >> >> I have replaced the "<Service Name" wit "Spooler, but the command does >> not >> work. Instead, it just tells me that DependOnService could not be found. >> >> Can anyone tell me how to get this working in a simple batch file? >> >> --Tom >> > > Where are you getting the string (in the parenthesis) that you are > searching through? Looks to me that you simply have a static string so > whatever you put there is all that can be parsed by the tokens > parameter. > > Run "sc /?" from a DOS shell. You'll have to redirect the output to a > file and then read the file to search for the info. Make sure when > using the 'query' directive that you include the trailing space after > the equals sign. First, thanks for the reply. Second, I think that I've solved the problem. You can read through the background, or skip to the end if you just want to see the solution that I found. Background ------------- I'm glad my post made some degree of sense because I was literally falling asleep at the keyboard as I was writing it up. Although, I do notice a few typos. Just to clarify, in the original command I have replaced "<Service Name>" with "Spooler". I assume that you understood what I intended, but just wanted to be clear. I got the command from this site: http://windowsitpro.com/article/articleid/85575/jsi-tip-10337-you-receive-error-1075-when-you-attempt-to-start-the-print-spooler-service-on-windows-xp.html The way I read that page it seems like the command is intended to list out all the services that are dependent on the service named in the command. But like you, I wondered if the command simply searches the text that is enclosed in quotes. It seems to me that the command is either not correct, or that I have really mis-interpreted the information on the page. Solution -------- You asked where I got the service name of "Spooler" that I was using in the command. I have a batch file that will list out all the service names with the associated display names. I looked at that batch file (I didn't write it) and found that it uses the sc command, which you also referenced. As you suggested, I ran cmd and did sc /?, where I found the EnumDepend option. So, running a command like: sc enumdepend rpcss (RPCSS is the Remote Procedure Call service) results in a list of all the services that depend on the RPC service. A person could then redirect the output into a text file. This is really all that I was looking for. I must have simply mis-understood the Web page (link above) from which I got that original command. Thanks for your help. --Tom
Guest Thomas M. Posted May 30, 2008 Posted May 30, 2008 Re: DependOnService > Solution > -------- > You asked where I got the service name of "Spooler" that I was using in > the command. I have a batch file that will list out all the service names > with the associated display names. I looked at that batch file (I didn't > write it) and found that it uses the sc command, which you also > referenced. As you suggested, I ran cmd and did sc /?, where I found the > EnumDepend option. So, running a command like: > > sc enumdepend rpcss (RPCSS is the Remote Procedure Call service) > > results in a list of all the services that depend on the RPC service. A > person could then redirect the output into a text file. This is really > all that I was looking for. I must have simply mis-understood the Web > page (link above) from which I got that original command. Okay, now I have a different problem. I currently have the following batch file. set /p ServiceName=Enter the service name: sc enumdepend %ServiceName% > ServiceDependencies.txt There are a couple of other lines that get echoed to the screen to give the user some instructions, but basically the two lines above are the whole show. The first line prompts for the name of the service and the second line takes that service name and outputs the results to a text file. If I enter "spooler" as the service name all is well because there is only one dependent service. However, if I enter "rpcss" which is the service name for the Remote Procedure Call service and which has a ton of dependent services, the resulting text file lists only 4 services and the last line of the file is, "Enum: more data, need 5214 bytes." I can stumble through the easy stuff, but I'm not a programmer. I'm guessing that this is telling me that more memory needs to be allocated to the output of the command, but I don't know that for certain and even if I'm right I don't know how to fix it. Can anyone tell me how to get around this problem so that the output file will contain a complete listing of the dependent services? --Tom
Guest VanguardLH Posted May 30, 2008 Posted May 30, 2008 Re: DependOnService "Thomas M." wrote in <news:#WOwWrpwIHA.4476@TK2MSFTNGP06.phx.gbl>: > sc enumdepend Run: sc enumdepend Notice what it says is its syntax. One of the parameters is a bufsize. I don't know what the default is. It complained about needing another 5214 bytes. I didn't bother to count the bytes in what it did manage to output. I just used a bufsize of 8192 and all of the output showed up without the bufsize error.
Guest Thomas M. Posted June 3, 2008 Posted June 3, 2008 Re: DependOnService "VanguardLH" <V@nguard.LH> wrote in message news:y9ydnVWubrAIEN3VnZ2dnUVZ_v3inZ2d@comcast.com... > "Thomas M." wrote in <news:#WOwWrpwIHA.4476@TK2MSFTNGP06.phx.gbl>: > >> sc enumdepend > > Run: > > sc enumdepend > > Notice what it says is its syntax. One of the parameters is a bufsize. > I don't know what the default is. It complained about needing another > 5214 bytes. I didn't bother to count the bytes in what it did manage to > output. I just used a bufsize of 8192 and all of the output showed up > without the bufsize error. Thanks! That did the trick. I had done "sc /?" from the command line, but it did not occur to me to try "sc enumdepend". You only see the <bufsize> parameter with that second command. Although, I just noticed that is you do "sc /?" and then answer "yes" to the question about wanting to see the help for the QUERY and QUERYEX commands (which I didn't do previously) you also see a <bufsize> parameter there and it indicates a default value of 4096. For those who are interested, here is my complete batch file. @Echo off cls ::Lists all the services running on the machine. sc query state= all ::Prompt the user to enter the service name Echo. Echo ************************************************* Echo This command must use the service name which can Echo be found in the list above. Echo ************************************************* Echo. set /p ServiceName=Enter the service name: :: Enumerates the services that are dependent on the specified service. sc enumdepend %ServiceName% 8192 > ServiceDependencies.txt --Tom
Recommended Posts