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.
Starting and Stopping Services in Windows
Moderator: DosItHelp
Re: Starting and Stopping Services in Windows
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.
(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
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
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:
It's easy to use an "if statement" with one of the variables, isn't it?
Regards
aGerman
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
psservice start/stop/restart etc included with pstools
http://technet.microsoft.com/en-us/sysi ... 96649.aspx
http://technet.microsoft.com/en-us/sysi ... 96649.aspx
Re: Starting and Stopping Services in Windows
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
'Net Start <service name>'
or
'Net Stop <service name>'
I hope you can get your head around this, if not, good luck.
Shanet
-
- Posts: 5
- Joined: 10 Jan 2010 14:57
- Location: U.S FL.
Re: Starting and Stopping Services in Windows
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
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