Link to home
Start Free TrialLog in
Avatar of christg
christg

asked on

List service with a batch file

Hi,

I want to know if there is a way to list all service that have startup type set to automatic with a batch file.

thanks
Avatar of Yan_west
Yan_west

Hmm you can list all running services with the net start command.

Just type net start at the command prompt, and it will give you all running services.
Avatar of christg

ASKER

Yes, I already tried that but I only want to have a list that contain only automatic services. I also tried with sc.exe with no good result.
Just open notepad and type

net start

and save it as services.bat

If you want to redirect the input in a text file you can write

Net start > services.txt

Or Net start >> services.txt to append to the file each time you run it.
If you are willing to spend a little bit of money, purchase Dameware NT Utilities. This is a very valuable piece of software that has numerous features. You will be able with this software to export alot of information about PC's on your network. One of which is the ability to export a list of services running on any PC on the network to a text file. You can downlod a 'trial' version of this software from www.dameware.com. Check it out. Good stuff
Avatar of christg

ASKER

What I ant to do it to schedule a batch file that will create a file that contain only services that are supposed to start automatically.

I know that there is a lot of nice utility on the market but I don't want to do the right - export to a file everynight !!

Hello,
here is a vb script that should accmoplish the task.
you can schedule the script to run or schedule a batch file to run that in turn will run the script.

open notepad >> copy and paste the following code >> save it with a .vbs extension.
It will create a file on the C drive called test.txt. Of course you can change this part to your liking (line 6)

'!!Begin Copy
strComputer = "."
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\test.txt", ForAppending, True)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select name from Win32_Service where StartMode = 'Auto'", , 48)
For Each objItem In colItems
 
   objTextFile.WriteLine objItem.Name
 
Next

objTextFile.Close

'!!End Copy

Let me know what changes we need to make
Avatar of christg

ASKER

Thanks mdiglio, now, is it possible to have an option that will sort automatic service that are not running into a file ?
ASKER CERTIFIED SOLUTION
Avatar of exx1976
exx1976
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
christg,
did exx1976 response answer your question?
I didn't understand what you meant by 'sort automatic service that are not running into a file'
(maybe I need more coffee)
I hope that worked for you

exx1976,
I always use those constants out of habit of learning wmi from the scriptomatic tool :)
this is an excerpt from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/scripting_api_constants.asp

to create a semisynchronous call, the iFlags parameter in an SWbemServices.ExecQuery_ call must contain two flags. The value of WbemFlagReturnImmediately is 16 and the value of WbemFlagForwardOnly is 32. Because the constants cannot be accessed by name, the values of these flags are combined, producing an iFlags value of 48
Avatar of christg

ASKER

Yes, it works with exx1976 response.

Thanks
Ahhh..  The scriptomatic tool..   I have looked at it a few times, but never used it.  I learned from the MS 2433 class and various books and code I found posted on the net...  I'll look into that MSDN article, thanks!!

Glad I could help christg, but I really think you should have split the points..   mdiglio did help you out..  I just happened to find the thread and added 4 or 5 lines to what he already had there...


-exx