Page 1 of 1
Starting and Stopping Services in Windows
Posted: 25 Mar 2010 07:08
by olarmy
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.
Re: Starting and Stopping Services in Windows
Posted: 25 Mar 2010 11:58
by aGerman
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.
Re: Starting and Stopping Services in Windows
Posted: 25 Mar 2010 12:27
by olarmy
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".
Re: Starting and Stopping Services in Windows
Posted: 25 Mar 2010 12:58
by aGerman
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
Re: Starting and Stopping Services in Windows
Posted: 26 Mar 2010 07:41
by sxekjb
psservice start/stop/restart etc included with pstools
http://technet.microsoft.com/en-us/sysi ... 96649.aspx
Re: Starting and Stopping Services in Windows
Posted: 04 Apr 2010 21:38
by shanet
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.
Shanet
Re: Starting and Stopping Services in Windows
Posted: 05 Apr 2010 10:14
by ENU_USER*.*
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