Link to home
Start Free TrialLog in
Avatar of sawred
sawred

asked on

How do you disable services from the CMD line

I setup a lot of XP machines, and I have to disable 10 services.  I am not allowed to use an image or ghost type application, and have to do all these machines manually.  I would like way to disable services from the CMD line, a batch file, a reg key something, anything where I can run 1 thing and it knocks out 10 services.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
done?
Avatar of sawred
sawred

ASKER

oBda I cannot tell you how 'cool' I think you are.  Thanks a lot.

Thanks to you I found this http://support.microsoft.com/?kbid=251192
Avatar of sawred

ASKER

Okay oBda, I got 1 to work so far.  But I have another question

This is from M$
Servicename
Specifies the name given to the service key in the Registry. Note that this is different from the display name, which is what you see with NET START and the Services Control Panel application. SC uses the service key name as the primary identifier for the service.


*** Where do you find the last part, service key name for each service? ***

I am trying to disable Fast User Switching, and Help and Support, am I to understand that svhost.exe calls netsvcs?
Is it a 2 parter, or let me rephrase the question,

Fast User Switching Compatibility
C:\WINDOWS\System32\svchost.exe -k netsvcs
&
Help and Support
C:\WINDOWS\System32\svchost.exe -k netsvcs

A couple of times I got
"(SC) OpenService failed 1060"  might have typed it incorrectly

This one worked
sc config defwatch start= disabled
Avatar of sawred

ASKER

Okay oBda, I got 1 to work so far.  But I have another question

This is from M$
Servicename
Specifies the name given to the service key in the Registry. Note that this is different from the display name, which is what you see with NET START and the Services Control Panel application. SC uses the service key name as the primary identifier for the service.


*** Where do you find the last part, service key name for each service? ***

I am trying to disable Fast User Switching, and Help and Support, am I to understand that svhost.exe calls netsvcs?
Is it a 2 parter, or let me rephrase the question,

Fast User Switching Compatibility
C:\WINDOWS\System32\svchost.exe -k netsvcs
&
Help and Support
C:\WINDOWS\System32\svchost.exe -k netsvcs

A couple of times I got
"(SC) OpenService failed 1060"  might have typed it incorrectly

This one worked
sc config defwatch start= disabled
The service key name can be identified using 'sc query'. You probably need to enlarge the buffersize, and you might want to pipe it through find, so that you just have a list of names.
That would turn out to be 'sc query bufsize= 4096 | find /i "service_name"'
Here's another approach using WMI:

set wmiService = GetObject ("winmgmts:Win32_Service.Name='FastUserSwitchingCompatibility'")
If wmiService.State = "Running" then
      wmiService.StopService()
End if
wmiService.ChangeStartMode("Disabled")
set wmiService = Nothing

You can also use the Win32_Service object to find out more things about a service than it's decent to ask :-)

More details at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_service.asp
And for the follow-up question, this might work.

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objServices = objWMIService.ExecQuery("Select * from Win32_Service",,48)

For Each objItem in objServices
    Wscript.Echo "============================"
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "DisplayName: " & objItem.DisplayName
    Wscript.Echo "Name: " & objItem.Name
Next
Avatar of sawred

ASKER

Ok I got it all working except for 3 of them

1.Fast User Switching Compatibility
2.Portable Media Serial Number Service
3.Universal Plug and Play Device Host

I cannot find the service name for these 3. Any help would be great.  

I am confused as to getting "sc query" working
And
those last 2 comments by DominicCronin look great, and I've had some programming but I don't know what WMI is? Requirements?  etc.
WMI = Windows management instrumentation

It's certainly part of the system in Win2K - I suspect you have to install it on older systems. To run the scripts above, copy and paste them into a text file, and give it a name with the extension .vbs

You can run them interactively, but in that case Wscript.Echo will generate a message box alert, which could get a bit tiresome! It's probably better to run them from a command prompt using the cscript command. For example:

cscript services.vbs

As for the names - on my system, running the above script reveals:

FastUserSwitchingCompatibility
WmdmPmSN
upnphost

This information is also available in the properties screen of the Services management snap-in (at least on my machine, which is running XP)
You can use the net service command line (in a batch)
or delete the appropriate entries in the registry with reg4.exe.

HKLM\SYSTEM\CurrentControlSet\Services\...
but of course, the best way is with sc.exe
Avatar of sawred

ASKER

Hey thanks everyone for your help

Thanks for the SC.EXE
Thanks for the Scripts
Thanks for the know how

All of it, my last questions are
What are the points on this board for?
What is the incentive?
How do I assign the points to everyone here that gave me an answer?

Below is a working example of the batch I made as well as turning this into a .com file. So everyone who reads it hear is the last place I am showing it.

This stops the service and disables it.

@echo off
cls
echo Disabling services now ....
echo now attempting to stop Help and Support
net stop "help and support"
sc config helpsvc start= disabled
echo Help and Support Disabled
echo ....

REM
REM


echo Now disabling NetMeeting Remote Desktop Sharing
sc config mnmsrvc start= disabled
echo Doesn't that feel nice
echo ....

REM
REM

echo Please stop mr automatic update
net stop "automatic updates"

echo No more Automatic Updates
sc config wuauserv start= disabled

echo System Restore Service now stopping
net stop "System Restore Service"
echo System Restore Now
sc config srservice start= disabled
echo OFF!!!

net stop "Smart Card"
sc config SCardSvr start= disabled

net stop "Error Reporting Service"
sc config ersvc start= auto

net stop "Smart Card Helper"
sc config SCardDrv start= disabled

net stop "SSDP Discovery Service"
sc config SSDPSRV start= disabled

net stop "themes"
sc config themes start= disabled



sc config "PolicyAgent" start= demand

net stop "Fast User Switching Compatibility"
sc config FastUserSwitchingCompatibility start= disabled
net stop "Portable Media Serial Number Service"
sc config WmdmPmSN start= disabled
net stop "Universal Plug and Play Device Host"
sc config upnphost start= disabled
The points are just there to be collected for the ones who answer for no particular reason other than to pile them up and to keep people from asking incessantly, because you only get so much (without paying).
To assign the points, you just accept the comment that helped you most as answer.
If you want to spend some additional points, you just open a new question worth the points, call it something like "points for <whoever>", wait for <whoever> to answer and then just accept it.