Starting and Stopping Services in Windows

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
olarmy
Posts: 2
Joined: 25 Mar 2010 06:56

Starting and Stopping Services in Windows

#1 Post by olarmy » 25 Mar 2010 07:08

I am very new to dos batch scripts and was wanting some advice from you all if that is cool.

I have 3 windows services that I would like to disable and stop. Then pause the script for me to do work on the server, then start back up the services with the appropriate "start_type" and start up the service again.

I would also like to check if the service is "disabled" first and if it is, then do not start that specific service at the end of script.


I hope this makes since. Thanks for any advice.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Starting and Stopping Services in Windows

#2 Post by aGerman » 25 Mar 2010 11:58

Have a look to NET START and NET STOP.
(for help use NET HELP START and NET HELP STOP)

Unfortunately I'm not so familar with this commands.

olarmy
Posts: 2
Joined: 25 Mar 2010 06:56

Re: Starting and Stopping Services in Windows

#3 Post by olarmy » 25 Mar 2010 12:27

I know that you can use sc.exe to find out what the "START_TYPE", but I am clueless in creating a script that will do what I want it to do. Not sure if you do some type of "if statemenet".

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Starting and Stopping Services in Windows

#4 Post by aGerman » 25 Mar 2010 12:58

Hmm OK. I had a look to the help of sc. The option qc returns informations about a service. I tried it with the BROWSER service:

Code: Select all

@echo off &setlocal
for /f "tokens=2* delims=: " %%a in ('sc qc BROWSER ^|findstr /i /c:"START_TYPE"') do set "STypeNumber=%%a" &set "SType=%%b"
echo %STypeNumber%
echo %SType%
pause


It's easy to use an "if statement" with one of the variables, isn't it?

Regards
aGerman

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

Re: Starting and Stopping Services in Windows

#5 Post by sxekjb » 26 Mar 2010 07:41

psservice start/stop/restart etc included with pstools

http://technet.microsoft.com/en-us/sysi ... 96649.aspx

shanet
Posts: 11
Joined: 04 Apr 2010 21:22

Re: Starting and Stopping Services in Windows

#6 Post by shanet » 04 Apr 2010 21:38

I found this out last night. It took me 2 minutes to understand, so its not that hard.

'Net Start <service name>'
or
'Net Stop <service name>'

I hope you can get your head around this, if not, good luck.

:twisted: Shanet :twisted:

ENU_USER*.*
Posts: 5
Joined: 10 Jan 2010 14:57
Location: U.S FL.

Re: Starting and Stopping Services in Windows

#7 Post by ENU_USER*.* » 05 Apr 2010 10:14

You didnt say what O.S. you are using or which services but I stop and start services all the time when doing a Unattended Install of XP or Vista/Win7. You can do it thru regedit or commandline. When I want to prevent Windows File Protection from kicking in or the access is denied message then I would disable the Cryptographic Service , Firewall, Security Center etc.
I also threw in the netsh as another way with the /y switch. (see below) or you can make a .reg file and add to your batch and call it Services.reg
with the following:
Windows Registry Editor Version 5.00

; Disable Services Not Needed
; 00000002=Automatic, 00000003=Manual, 00000004=Disabled

Windows Firewall/Internet Connection Sharing (ICS)
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess]
"Start"=dword:00000004

Security Center
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wscsvc]
"Start"=dword:00000004


Code: Select all

@Echo Off
: ***DISABLE SERVICES***
: Sets Startup type to disable and Stops Service Status
sc config CryptSvc start= disabled
net stop CryptSvc /y
netsh firewall set opmode disable
:
: ***RESTART SERVICES***
sc config CryptSvc start= Auto
net start CryptSvc

exit

Post Reply